GNOME Bugzilla – Bug 315883
Repeating RelaxNG validation on an invalid document returns valid on second attempt
Last modified: 2017-06-12 19:06:09 UTC
Please describe the problem: I have a RelaxNG schema and a document that does not conform to that schema. attempting to validate it the first time shows the appropriate errors and says that the document does not validate. However, if I then attempt to validate the same xmlDocPtr again, xmlRelaxNGValidateDoc says that it is valid. Steps to reproduce: 1. Apply the attached patch to testRelax.c 2. cd test/relaxng 3. ../../testRelax docbook.rng docbook_0.xml Actual results: [relaxng]$ ../../testRelax docbook.rng docbook_0.xml docbook_0.xml:1160: element para: Relax-NG validity error : Did not expect element mdash there [... elided for brevity] docbook_0.xml:1905: element para: Relax-NG validity error : Did not expect element mdash there docbook_0.xml:1905: element para: Relax-NG validity error : Element para has extra content: mdash docbook_0.xml fails to validate docbook_0.xml validates Expected results: [relaxng]$ ../../testRelax docbook.rng docbook_0.xml docbook_0.xml:1160: element para: Relax-NG validity error : Did not expect element mdash there [... elided for brevity] docbook_0.xml:1905: element para: Relax-NG validity error : Did not expect element mdash there docbook_0.xml:1905: element para: Relax-NG validity error : Element para has extra content: mdash docbook_0.xml fails to validate docbook_0.xml:1160: element para: Relax-NG validity error : Did not expect element mdash there [... elided for brevity] docbook_0.xml:1905: element para: Relax-NG validity error : Did not expect element mdash there docbook_0.xml:1905: element para: Relax-NG validity error : Element para has extra content: mdash docbook_0.xml fails to validate Does this happen every time? No, only on some schema/document pairs. I haven't been able to find a common pattern. Other information: --- libxml2-2.6.21/testRelax.c 2005-01-04 06:49:47.000000000 -0800 +++ testRelax.c 2005-09-09 19:34:34.000000000 -0700 @@ -143,6 +143,23 @@ int ret; ctxt = xmlRelaxNGNewValidCtxt(schema); + xmlRelaxNGSetValidErrors(ctxt, + (xmlRelaxNGValidityErrorFunc) fprintf, + (xmlRelaxNGValidityWarningFunc) fprintf, + stderr); + ret = xmlRelaxNGValidateDoc(ctxt, doc); + if (ret == 0) { + printf("%s validates\n", argv[i]); + } else if (ret > 0) { + printf("%s fails to validate\n", argv[i]); + } else { + printf("%s validation generated an internal error\n", + argv[i]); + } + xmlRelaxNGFreeValidCtxt(ctxt); + + /* Try again */ + ctxt = xmlRelaxNGNewValidCtxt(schema); xmlRelaxNGSetValidErrors(ctxt, (xmlRelaxNGValidityErrorFunc) fprintf, (xmlRelaxNGValidityWarningFunc) fprintf,
I can confirm this at least up to 2.6.26. It doesn't happen for all schemas or for all XML you validate against, but this is a minimal combination that does it: Relax NG: <?xml version="1.0" encoding="UTF-8"?> <grammar ns="http://some.namespace.org" xmlns="http://relaxng.org/ns/structure/1.0"> <start> <element name="root"> <element name="sub"><text/></element> </element> </start> </grammar> document to validate: <root xmlns="http://some.namespace.org"> <sub><something /></sub> </root>
Okay finally took the time to fix, just a matter of cleaning up the ->psvi fields of elements: paphio:~/XML -> ./testRelax tst.rng tst.xml tst.xml:2: element something: Relax-NG validity error : Did not expect element something there tst.xml fails to validate tst.xml:2: element something: Relax-NG validity error : Did not expect element something there tst.xml fails to validate paphio:~/XML -> Fixed in git, thanks for the report ! Daniel