After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 315883 - Repeating RelaxNG validation on an invalid document returns valid on second attempt
Repeating RelaxNG validation on an invalid document returns valid on second a...
Status: RESOLVED FIXED
Product: libxml2
Classification: Platform
Component: relaxng
2.6.21
Other All
: Normal normal
: ---
Assigned To: Daniel Veillard
libxml QA maintainers
Depends on:
Blocks:
 
 
Reported: 2005-09-10 03:20 UTC by Robert Kern
Modified: 2017-06-12 19:06 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Robert Kern 2005-09-10 03:20:50 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,
Comment 1 faassen 2006-12-21 15:57:43 UTC
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>
Comment 2 Daniel Veillard 2009-08-21 15:36:33 UTC
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