Subject: | Revalidation of dynamically-modified documents fails when using namespaces |
Remember the bug with document revalidation? The one that was fixed in
r785? Well, it seems it's still there if you use namespaces.
See attached a patch against current trunk, adding a failing test case.
To aid a bit when debugging, see the comments in both the test case
document and the test XML schema: they contain a variant _without_
namespaces, which works as intended.
Subject: | nstest.patch |
Index: test/relaxng/ns.rng
===================================================================
--- test/relaxng/ns.rng (revision 0)
+++ test/relaxng/ns.rng (revision 0)
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes" -->
+<grammar ns="http://xmlns.example.com/2007/test/datastore" xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
+ <!-- Document -->
+ <start>
+ <ref name="Datastore"/>
+ </start>
+ <define name="Datastore">
+ <element name="datastore">
+ <ref name="Data"/>
+ </element>
+ </define>
+ <define name="Data">
+ <element name="data">
+ <ref name="Active"/>
+ </element>
+ </define>
+ <!-- Structure elements -->
+ <define name="Active">
+ <element name="active">
+ <choice>
+ <interleave>
+ <zeroOrMore>
+ <ref name="Element"/>
+ </zeroOrMore>
+ </interleave>
+ <empty/>
+ </choice>
+ </element>
+ </define>
+ <define name="Element">
+ <element name="element">
+ <choice>
+ <ref name="Id"/>
+ <ref name="Did"/>
+ </choice>
+ <interleave>
+ <optional>
+ <ref name="Title"/>
+ </optional>
+ <optional>
+ <ref name="Payload"/>
+ </optional>
+ </interleave>
+ </element>
+ </define>
+
+ <!-- Simple elements -->
+ <define name="Title">
+ <element name="title">
+ <data type="token"/>
+ </element>
+ </define>
+ <define name="Payload">
+ <element name="payload">
+ <data type="token"/>
+ </element>
+ </define>
+ <!-- Attributes -->
+ <define name="Id">
+ <attribute name="id">
+ <data type="ID"/>
+ </attribute>
+ </define>
+ <define name="Did">
+ <attribute name="did">
+ <data type="token"/>
+ </attribute>
+ </define>
+</grammar>
Index: t/25relaxng.t
===================================================================
--- t/25relaxng.t (revision 824)
+++ t/25relaxng.t (working copy)
@@ -11,7 +11,7 @@
use XML::LibXML;
if ( XML::LibXML::LIBXML_VERSION >= 20510 ) {
- plan tests => 13;
+ plan tests => 17;
}
else {
plan tests => 0;
@@ -28,6 +28,7 @@
my $validfile = "test/relaxng/demo.xml";
my $invalidfile = "test/relaxng/invaliddemo.xml";
my $demo4 = "test/relaxng/demo4.rng";
+my $namespace = "test/relaxng/ns.rng";
print "# 1 parse schema from a file\n";
{
@@ -113,5 +114,55 @@
}
+print "# 6 re-validate a modified document\n";
+{
+ my $parser = new XML::LibXML();
+
+ my $rngschema = XML::LibXML::RelaxNG->new(location => $namespace);
+ my $doc = $parser->parse_string(<<EOD);
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE datastore SYSTEM "//test/test/datastore" [
+<!ATTLIST element id ID #IMPLIED>
+]>
+<!-- datastore -->
+<datastore xmlns="http://xmlns.example.com/2007/test/datastore">
+ <data>
+ <active>
+ <element id="uuidtest1">
+ <title>Ze element</title>
+ <payload>Ze element payload</payload>
+ </element>
+ </active>
+ </data>
+</datastore>
+EOD
+ eval{$rngschema->validate($doc);}; ok (!$@);
+
+ my $node = $doc->createElement("element");
+
+ my $title = $doc->createElement("title");
+ $title->appendText("Annoying tests are annoying");
+ $node->appendChild($title);
+
+ my $payload = $doc->createElement("payload");
+ $payload->appendText("some payload");
+ $node->appendChild($payload);
+
+ $node->setAttribute('id', 'uuidIamAtestElement');
+
+ my ($active) = $doc->getElementsByTagName("active");
+ eval{$rngschema->validate($doc);}; ok (!$@);
+ $active->appendChild($node);
+
+ # If there's a bug in the dynamically-generated content, this test
+ # will always fail no matter what. Hence, we reparse the document
+ # and validate that (that always works) to make sure our
+ # modifications are really valid
+ my $reparsed_doc = $parser->parse_string($doc->toString);
+ eval{$rngschema->validate($reparsed_doc);}; ok (!$@);
+
+ eval{$rngschema->validate($doc);}; ok (!$@);
+}
+
} # Version >= 20510 test