Peter Morris [Droopy eyes software] wrote:
I need a little help with XSD,
I need to do two things.
1) Create a key on brandGroup.name
2) Ensure that brand.groupName refers to a key on brandGroup.name
Here is an example schema
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="1.0">
<xs:element name="data">
<xs:complexType >
<xs:sequence>
<xs:element name="brandData ">
<xs:complexType >
<xs:sequence>
<xs:element name="brandGrou ps">
<xs:complexType >
<xs:sequence>
<xs:element name="brandGrou p" maxOccurs="unbo unded">
<xs:complexType >
<xs:sequence>
<xs:element name="name" type="xs:string " />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="brands">
<xs:complexType >
<xs:element name="brand" maxOccurs="unbo unded">
<xs:complexType >
<xs:sequence>
<xs:element name="name" type="xs:string " />
<xs:element name="groupName " type="xs:string " />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:key name="brandGrou pName">
<xs:selector xpath="brandGro ups/brandGroup" />
<xs:field xpath="name" />
</xs:key>
<xs:keyref name="brandRefe rsGroup" refer="brandGro upName">
<xs:selector xpath="brands/brand" />
<xs:field xpath="groupNam e" />
</xs:keyref>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Note that your sample XML provided (even after making it well-formed) is
not valid against that schema as you have two
<brandGroup>
<name>Group2</name>
</brandGroup>
elements which is not allowed if name is defined as a key.
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/