RelaxNG diagnostics / errors often unhelpful to misleading
When validating using rng, libxml2's error messages are singularly unhelpful, often going no further than a complex way of saying "the document is invalid". This doesn't seem inherent to relaxng as Jing does provide helpful error messages.
Test case: test.xml, test.rng the issue is a trailing "/" after one of the field tags (assumed to be some sort of typo).
> xmllint --noout --relaxng test.rng test.xml
test.xml:2: element item: Relax-NG validity error : Element root has extra content: item
test.xml fails to validate
> jing test.rng test.xml
test.xml:5:3: error: text not allowed here; expected the element end-tag or element "field"
jing pinpoints the source of the issue quite specifically though not entirely correctly (the line:column point to the end-tag rather than the extra text), libxml2 just gives up and states that the entire thing is broken.
I'm guessing the issue comes down to reducing from choice patterns, as removing some of the choices makes for somewhat better error messages (though nowhere near jing's in specificity):
-
if the "root" name is made non-choice, or the "root" pattern is made non-recursive (the rng:ref line 16 is removed) libxml does state the correct error though it doesn't pinpoint where the error occurs (beyond the parent element):
test.xml:2: element item: Relax-NG validity error : Did not expect text in element item content test.xml:2: element item: Relax-NG validity error : Element item has extra content: text test.xml fails to validate
-
if the
<text/>
pattern is removed from the root element, libxml gets much chattier and better hints at the issue though it also provides a bunch of misleading cues:test.xml:2: element item: Relax-NG validity error : Expecting an element got text test.xml:3: element field: Relax-NG validity error : Element item has extra content: field test.xml:2: element item: Relax-NG validity error : Element root has extra content: item test.xml fails to validate
See also on the old tracker: