fhurtad
February 1st, 2012, 11:33 AM
Hi all:
I am trying to use keys and keyrefs in XSD without any success (I am a newbie in XSD). For example, this XSD does not work as the attached XML object demonstrates:
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/sc"
xmlns:fh="http://www.example.org/sc" elementFormDefault="qualified">
<element name="Orders">
<complexType>
<sequence minOccurs="1" maxOccurs="unbounded">
<element name="AnOrder">
<complexType>
<attribute name="orderId" type="string" use="required" />
</complexType>
</element>
</sequence>
</complexType>
<unique name="orderKey">
<selector xpath="Orders/Order" />
<field xpath="@orderId" />
</unique>
</element>
</schema>
I thought that with this definitions any order must have a unique orderId attribute.
The prof that this does not work is this XML object (I am validating the objects with the Eclipse support tools):
<?xml version="1.0" encoding="UTF-8"?>
<fh:Orders xmlns:fh="http://www.example.org/sc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.example.org/sc sc.xsd ">
<fh:AnOrder orderId="1" />
<fh:AnOrder orderId="1" />
</fh:Orders>
Coul anybody with some skills in XSD help me with this?
I am trying to use keys and keyrefs in XSD without any success (I am a newbie in XSD). For example, this XSD does not work as the attached XML object demonstrates:
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/sc"
xmlns:fh="http://www.example.org/sc" elementFormDefault="qualified">
<element name="Orders">
<complexType>
<sequence minOccurs="1" maxOccurs="unbounded">
<element name="AnOrder">
<complexType>
<attribute name="orderId" type="string" use="required" />
</complexType>
</element>
</sequence>
</complexType>
<unique name="orderKey">
<selector xpath="Orders/Order" />
<field xpath="@orderId" />
</unique>
</element>
</schema>
I thought that with this definitions any order must have a unique orderId attribute.
The prof that this does not work is this XML object (I am validating the objects with the Eclipse support tools):
<?xml version="1.0" encoding="UTF-8"?>
<fh:Orders xmlns:fh="http://www.example.org/sc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.example.org/sc sc.xsd ">
<fh:AnOrder orderId="1" />
<fh:AnOrder orderId="1" />
</fh:Orders>
Coul anybody with some skills in XSD help me with this?