D
Don Bate
I'm having a problem with the "unique" feature of XML Schema. I'm
relatively new to using this feature so it may be that I'm
misunderstanding something. Let's assume that I have the following
schema:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xs:element name="a">
<xs:complexType>
<xs:sequence>
<xs:element ref="b" maxOccurs="unbounded"/>
<xs:element ref="c" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:unique name="xUnique">
<xs:selector xpath="a|b"/>
<xs:field xpath="@x"/>
</xs:unique>
</xs:element>
<xs:element name="b">
<xs:complexType>
<xs:attribute name="x" type="xs:string"
use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="c">
<xs:complexType>
<xs:attribute name="x" type="xs:string"
use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>
where an element "a" has two child elements "b" and "c". Each of these
child elements have a string attribute "x". "x" is supposed to be unique
within "a" regardless of whether it's in "b" or "c". I believe that the
above schema captures that.
However, the following document is valid according to XMLSpy and Xerces
when I believe that it is invalid:
<?xml version="1.0" encoding="UTF-8"?>
<a xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="test.xsd">
<b x="foo"/>
<c x="foo"/>
</a>
Am I doing something wrong? Do I not have my xpath selector correctly
written? Is this a bug?
Don Bate
relatively new to using this feature so it may be that I'm
misunderstanding something. Let's assume that I have the following
schema:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xs:element name="a">
<xs:complexType>
<xs:sequence>
<xs:element ref="b" maxOccurs="unbounded"/>
<xs:element ref="c" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:unique name="xUnique">
<xs:selector xpath="a|b"/>
<xs:field xpath="@x"/>
</xs:unique>
</xs:element>
<xs:element name="b">
<xs:complexType>
<xs:attribute name="x" type="xs:string"
use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="c">
<xs:complexType>
<xs:attribute name="x" type="xs:string"
use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>
where an element "a" has two child elements "b" and "c". Each of these
child elements have a string attribute "x". "x" is supposed to be unique
within "a" regardless of whether it's in "b" or "c". I believe that the
above schema captures that.
However, the following document is valid according to XMLSpy and Xerces
when I believe that it is invalid:
<?xml version="1.0" encoding="UTF-8"?>
<a xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="test.xsd">
<b x="foo"/>
<c x="foo"/>
</a>
Am I doing something wrong? Do I not have my xpath selector correctly
written? Is this a bug?
Don Bate