[xml] Problem in error reporting when using key / keyref constraints in Schemas ?



Hi,

I am using key / keyref constraints in my schema, and in some cases, xmllint reports errors concerning keyref constraint even if this constraint is correct :

Here is my schema test.xsd :
<?xml version=" 1.0" encoding="ISO-8859-1"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:element name="ELEMENTS">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="element" type="xsd:string"/>
        <xsd:element name="element2" type="xsd:string"/>
      </xsd:sequence>
    </xsd:complexType>
    <xsd:key name="key">
      <xsd:selector xpath="element2"/>
      <xsd:field xpath="."/>
    </xsd:key>
    <xsd:keyref name="keyref" refer="key">
      <xsd:selector xpath="element"/>
      <xsd:field xpath="."/>
    </xsd:keyref>
  </xsd:element>
</xsd:schema>

And here is my XML file test.xml :
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<ELEMENTS>
  <element>test2</element>
  <elementUndeclared>test3</elementUndeclared>
  <element2>test2</element2>
</ELEMENTS>


$ xmllint --version
$ xmllint: using libxml version 20627
   compiled with: Threads Tree Output Push Reader Patterns Writer SAXv1 FTP HTTP DTDValid HTML Legacy C14N Catalog XPath XPointer XInclude Iconv ISO8859X Unicode Regexps Automata Expr Schemas Schematron Modules Debug Zlib

$ xmllint --schema test.xsd test.xml --noout
test.xml:4: element elementUndeclared: Schemas validity error : Element 'elementUndeclared': This element is not expected. Expected is ( element2 ).
test.xml:3: Schemas validity error : Element 'element': No match found for key-sequence ['test2'] of keyref 'keyref'.
test.xml fails to validate

The last error doesn't seem to be correct (the value test2 is carried by element2). I guess that the key constraint carried by 'element2' is not filled in correctly because of the error carried by the preceding element, then the keyref  constraint doesn't find any corresponding value.

Whith the following XML file test2.xml (the elementUndeclared is put after element2), the error concerning keyref values disappears and the output is fine :
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<ELEMENTS>
  <element>test2</element>
  <element2>test2</element2>
  <elementUndeclared>test3</elementUndeclared>
</ELEMENTS>

$ xmllint --schema test.xsd test2.xml --noout
test2.xml:5: element elementUndeclared: Schemas validity error : Element 'elementUndeclared': This element is not expected.
test2.xml fails to validate

Is it a bug or an expected behaviour ?

Regards,

Fabrice



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]