[xml] xs:IDREF does not work in XML Schema



Hi,

 

I've just noticed that if the XML Schema is used for validation of the document, the xs:IDREF type does not seem to work. It essentially behaves like an xs:NCName - checks the lexical constraints, but does not check that it refers to a valid xs:ID anywhere in the document.

 

Here is an example:

 

---8<--- 1.xml ---8<---

<?xml version="1.0"?>

<root>

<def id="a1"/>

<ref idref="a2"/>

</root>

---8<-------------8<---

 

---8<--- 1.xsd ---8<---

<?xml version="1.0"?>

<xs:schema elementFormDefault="qualified" attributeFormDefault="unqualified"

xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="root">

<xs:complexType>

<xs:sequence>

<xs:element name="def" minOccurs="0" maxOccurs="unbounded">

<xs:complexType>

<xs:attribute name="id" type="xs:ID" use="required"/>

</xs:complexType>

</xs:element>

<xs:element name="ref" minOccurs="0" maxOccurs="unbounded">

<xs:complexType>

<xs:attribute name="idref" type="xs:IDREF" use="required"/>

</xs:complexType>

</xs:element>

</xs:sequence>

</xs:complexType>

</xs:element>

</xs:schema>

---8<-------------8<---

 

$ xmllint --noout --schema 1.xsd 1.xml

1.xml validates

 

Using libxml2 version 2.9.1. DTD validation seems to work fine with IDREF:

 

---8<--- 1.dtd ---8<---

<!ELEMENT root (def*,ref*)>

<!ELEMENT def EMPTY>

<!ATTLIST def id ID #REQUIRED>

<!ELEMENT ref EMPTY>

<!ATTLIST ref idref IDREF #REQUIRED>

---8<-------------8<---

 

$ xmllint --noout --dtdvalid 1.dtd 1.xml

1.xml:5: element ref: validity error : IDREF attribute idref references an unknown ID "a2"

 

Am I missing something in the schema definition? Or is it a bug in libxml2?

 

Regards,

Alexey.



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