XML technologies / Schematron / User-friendly error messages / Error messages in detail

(Excerpt from "Schematron - Effiziente Business Rules für XML-Dokumente", chapter 6)

A good message lets even the so-called DAU, programmers’ German shorthand for the “dumbest conceivable user”, understand and fix the error. It must also be concise, so users encountering many different errors can keep an overview and identify each immediately.

Further links

Schematron offers two ways to balance these needs. First, elements (including <pattern>, <rule>, <assert> or <report>) can receive a see attribute containing a URI turned into a further link. The message identifies the error so users recognize and fix it. If insufficient, the link leads to a detailed error reference or the relevant schema documentation.

A link can only lead to general information written independently of the instance. Variable information must therefore accompany the original message.

<rule context="arc:nutzlast">
  <report test="number(//arc:nutzlast) &lt; sum(//arc:gewicht)" see="http://www.schematron.info/error42">Fehler 42: Überschreitung der Nutzlast (<value-of select="sum(//arc:gewicht)"/> kg): Gesamtgewicht: <value-of select="//arc:nutzlast"/> kg; Überschuss: <value-of select="sum(//arc:gewicht) - number(//arc:nutzlast)"/> kg.</report>
</rule>

oXygen status-bar output:

Schematron error message in oXygen

Figure: Schematron error message in oXygen

Contents of the linked website:

Schematron error message on a web page

Figure: Schematron error message on a web page

Here the message contains only essential context-dependent information, while the reference supplies a detailed, context-independent description.

Suggested solutions

Another way to separate the message from its description uses element <diagnostic>. As with elements <report> and <assert>, Schematron makes a purely semantic distinction. Each message—every <report> or <assert> element—can have a suggested solution through attribute diagnostics. This separates the error description from instructions to fix it. How do we create such a solution? Let us modify our ark schema again.

<schema xmlns="http://purl.oclc.org/dsdl/schematron"> 
  […] 
  <pattern> 
    <rule context="arc:tier"> 
      <report diagnostics="Anzahl" test="count(//arc:tier[arc:art=current()/arc:art]) &gt; 2">In der  Arche gibt es mehr als zwei Tiere dieser Art.</report> 
    </rule> 
  </pattern> 
  <diagnostics> 
    <diagnostic id="Anzahl">Noah, du hast  <value-of select="count(//arc:tier[arc:art=current()/arc:art])"/>  Tiere von der Gattung <value-of select="arc:art"/> in diesem  Zimmer beherbergt. Es müssen jedoch immer 2 Tiere einer Art in einem  Zimmer untergebracht sein. Du musst also  <value-of select="count(//arc:tier[arc:art=current()/arc:art]) -  2"/> Tier(e) dieser Art entfernen.</diagnostic> 
  </diagnostics> 
</schema> 

Create a top-level <diagnostics> element, a child of the root, as a container for one or several solutions. Each solution uses a <diagnostic> element—without a final s—and an id attribute. Its description is the content of the <diagnostic> element. To assign it to a message, add to the <report> or <assert> element a diagnostics attribute referencing its ID. Here the solution’s ID is »Anzahl«. Thus the <report> element also has attribute diagnostics with the IDREF value »Anzahl«.

A short message can thus gain a longer explanation of the fix. Unlike links, solutions can contain variable information: the rule’s context node transfers to the solution. As shown, a <diagnostic> element can contain a <value-of> element.

Link or suggested solution?

In practice, the implementation determines the choice: neither feature is mandatory in Schematron, and support varies. If support or presentation does not decide it, both may be combined. Suggested solutions can include variable text. A further link, by contrast, has only textual content and leaves presentation of the suggested solution to the implementation. A website can use graphics and networks of links, offering more scope for an appealing description.

   

 

 

 

back to top