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 312957 - key/keyref validation passes incorectly when root element has an attribute defined
key/keyref validation passes incorectly when root element has an attribute de...
Product: libxml2
Classification: Platform
Component: general
Other All
: Normal normal
: ---
Assigned To: Daniel Veillard
libxml QA maintainers
Depends on:
Reported: 2005-08-09 01:27 UTC by Carol Hunter
Modified: 2009-08-15 18:40 UTC
See Also:
GNOME target: ---
GNOME version: ---

Test schema. (1.37 KB, text/xml)
2005-08-09 01:29 UTC, Carol Hunter
Test xml. (322 bytes, text/xml)
2005-08-09 01:30 UTC, Carol Hunter

Description Carol Hunter 2005-08-09 01:27:55 UTC
Please describe the problem:
I have a simple xml schema that uses key/keyref to constrain identity.

In the schema I have defined an attribute called name on the root element.

When the optional name attribute is present in the root element an invalid xml
file (invalid keyref value) passes validation. If the root element name
attribute is removed from the xml the validation fails as expected.

The behaviour is consistent between xmllint and my own application which calls
the libxml2 API directly.

As an aside, xmlspy validates the file correctly whether the root element
attribute is present or not.

Steps to reproduce:
1. xmllint  -noout -schema test.xsd test.xml
2. "test.xml validates"
3. Remove the root element attribute Name="test"
4. xmllint  -noout -schema test.xsd test.xml
5. test.xml:2: element family: Schemas validity error : Element 'family': No
match found for key-sequence ['annie'] of key reference 'sibling_key_ref'.
test.xml fails to validate: 1877

Actual results:
As above.

Expected results:
I expect the validation error reported in step 5 to be reported whether or not
the root element attribute is present.

Does this happen every time?

Other information:
<?xml version="1.0" encoding="ISO-8859-1"?>
<family xmlns:xsi=""
xsi:noNamespaceSchemaLocation="test.xsd" name="test">
    	<sibling name="gill"/>
    	<sister name="gill"/>
    	<sister name="annie"/>

<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema xmlns:xs="">

  <xs:element name="family" type="family_type">
      <xs:key name="sibling_key">
        <xs:selector xpath="siblings/sibling"/>
        <xs:field xpath="@name"/>
      <xs:keyref name="sibling_key_ref" refer="sibling_key">
        <xs:selector xpath="sisters/sister"/>
        <xs:field xpath="@name"/>
    <xs:complexType name="family_type">
        <xs:element name="siblings" type="siblings_type" />
        <xs:element name="sisters" type="sisters_type"  />
      <xs:attribute name="name" type="xs:string"/>
    <xs:complexType name="siblings_type">
        <xs:element name="sibling" type="sibling_type" minOccurs="0"  
maxOccurs="unbounded" />
    <xs:complexType name="sisters_type">
        <xs:element name="sister" type="sister_type" minOccurs="0"  
maxOccurs="unbounded" />
	<xs:complexType name="sibling_type">
		<xs:attribute name="name" type="xs:string"/>
	<xs:complexType name="sister_type">
		<xs:attribute name="name" type="xs:string"/>
Comment 1 Carol Hunter 2005-08-09 01:29:45 UTC
Created attachment 50426 [details]
Test schema.
Comment 2 Carol Hunter 2005-08-09 01:30:20 UTC
Created attachment 50427 [details]
Test xml.
Comment 3 kbuchcik 2005-08-09 12:52:50 UTC
Fixed in CVS head, xmlschemas.c revision 1.165.

Streaming XPath states were not popped in every case in
xmlSchemaVAttributesComplex(), thus failed to resolve correctly
for subsequent input.

Thanks for this report! Seems like IDCs still did not work in
many cases for real life scenarios in Libxml2 2.6.20.

The funny thing is that this obvious scenario is not covered by
the W3C XML Schema test suite.

I added your test to the regression tests.
Comment 4 Daniel Veillard 2005-09-05 09:01:12 UTC
This should be closed by release of libxml2-2.6.21,