Re: [xml] Question about error reporting when using key / keyref constraints in Schema



Hi,

On Thu, 2005-08-11 at 13:14 +0200, GUY Fabrice wrote:
Hi, 

I'm using key / keyref constraints in my schema, and in case of error
the behaviour of the report message is not the same with
libxml2-2.6.19 and libxml2-2.6.20 :
- with the 2.6.19 version, the error is carried by the element which
produces the error (which is fine)
- but with the 2.6.20 version, the error is carried by the root
element, so there is no simple way to know which element is incorrect.

Here is my schema :
<?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" minOccurs="0"
maxOccurs="unbounded"/>
        <xsd:element name="element2" type="xsd:string" minOccurs="0"
maxOccurs="unbounded"/>
      </xsd:sequence>
    </xsd:complexType>
    <xsd:key name="key">
      <xsd:selector xpath="element"/>
      <xsd:field xpath="."/>
    </xsd:key>
    <xsd:keyref name="keyref" refer="key">
      <xsd:selector xpath="element2"/>
      <xsd:field xpath="."/>
    </xsd:keyref>
  </xsd:element>
</xsd:schema>


And my xml file :
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<ELEMENTS>
<element>test1</element><element2>test</element2>
</ELEMENTS>


- xmllint (version 2.6.19) outputs :
test.xml:3: element element2: Schemas validity error : Element
'element2' [keyRef 'keyref']: No matching key-sequence found.
test.xml fails to validate

- and xmllint (version 2.6.20) ouputs :
test.xml:2: element ELEMENTS: Schemas validity error : Element
'ELEMENTS': No match found for key-sequence ['test'] of key reference
'keyref'.
test.xml fails to validate

Is it a bug or is it a normal / expected behaviour ?

This is expected, but I understand that it does not help chasing
instance errors.
We changed the behaviour due to streaming validation. Keyrefs
can be only examined when we have traversed all content of the element
for which the keyref was defined (ELEMENTS in this case). I.e. we
need a complete list of all existing key/unique values in the
content to be able to say if a keyref has a correspondent.
Since, for streaming validation, this would mean saving all target
node informations - to be able to report the exact error prone node -
until we are finished with the content, we would loose the profit of
streaming validations: memory. Now, we could save the node
information in the case where we don't use streaming validation,
but this would result in different results for streaming/node-tree
validation. I dunno if such an inconsistency is appropriate,
so feedback from the list is mostly welcome.

By the way, I tested this with Xerces-J 2.7.1:

keyref.xml:7,12: (Error) Key 'keyref' with value 'test' not found for
identity constraint of element 'ELEMENTS'.
(the line number points to the end tag of ELEMENTS by the way) 

Xerces uses the same mechanism as we do.

Greetings,

Kasimier



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