- From: Gary Robertson <gazinyork@hotmail.com>
- Date: Fri, 5 Oct 2001 07:51:22 -0400 (EDT)
- To: <xmlschema-dev@w3.org>
I want the name attribute of an element and the name attribute
of one of its (multiple instance) child elements to form a unique
key. I would have though this a fairly simple requirement but
it is rejected because one of the two fields evaluates to more
than one node.
Am I missing something? Does anybody know the right way for
me to meet my requirement?
Here's an example of a (correct) file I would like to validate. Note
object and state names are unique in combination.
<?xml version="1.0" encoding="UTF-8"?>
<Repository xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="M:\MooD\DEV\Sydney\MooDXml\XmlSchemas\comboke
y.xsd">
<Object name="object 1">
<State name="state 1"/>
<State name="state 2"/>
</Object>
<Object name="object 2">
<State name="state 1"/>
<State name="state 2"/>
</Object>
</Repository>
Here is the schema, with illegal key, I wanted to use:
<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XML Spy v4.0.1 U (http://www.xmlspy.com) by Gary Robertson
(MooD International) -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="StateType">
<xs:attribute name="name" type="xs:string" use="required"/>
</xs:complexType>
<xs:complexType name="ObjectType">
<xs:sequence>
<xs:element name="State" type="StateType" minOccurs="0"
maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="name" type="xs:string" use="required"/>
</xs:complexType>
<xs:element name="Repository"> <!-- root element -->
<xs:complexType>
<xs:sequence>
<xs:element name="Object" type="ObjectType" minOccurs="0"
maxOccurs="unbounded">
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:key name="StateNameKey">
<xs:selector xpath="Object"/>
<xs:field xpath="@name"/>
<xs:field xpath="State/@name"/> <!-- parser objects to this because it
evaluates to multiple nodes -->
</xs:key>
</xs:element>
</xs:schema>
Gaz Robertson
Received on Friday, 5 October 2001 09:54:15 UTC