Thanks, Eddie. I did what you suggested too, and retested again after reading your message. The parser still doesn't complain.
-Shengyou
At 10:01 AM 06/20/2002 +1000, Eddie Robertsson wrote:
Hi,
<?xml version="1.0" encoding="UTF-8"?> <xs:schema targetNamespace="http://www.bts.com/pcsp" xmlns="http://www.bts.com/pcsp" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> <xs:element name="Contact"> <xs:complexType> <xs:sequence> <xs:element name="Name" type="xs:string"/> <xs:element name="Title" type="xs:string"/> <xs:element name="Phone" type="xs:string"/> <xs:element name="Email" type="xs:string"/> </xs:sequence> </xs:complexType> <xs:key name="ContactKey"> <xs:selector xpath="Contact"/> <xs:field xpath="Name"/> </xs:key> </xs:element> <xs:element name="ListOfContacts"> <xs:complexType> <xs:sequence> <xs:element ref="Contact" minOccurs="0" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>
The problem is that the key is defined in the wrong place. In W3C XML Schemas the key should be defined on the element which defines the scope of the uniqueness (1), the selector element should select the element that should be unique (2) and the field should identify the key (3). In your case 1, 2 and 3 are as follows:
(1) ListOfContacts (2) Contact (3) Name
So, you key should be defined on the ListOfContacts element, the selector should select the Contact element and the field should identify the Name element:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://www.bts.com/pcsp"
xmlns="http://www.bts.com/pcsp" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="Contact">
<xs:complexType>
<xs:sequence>
<xs:element name="Name" type="xs:string"/>
<xs:element name="Title" type="xs:string"/>
<xs:element name="Phone" type="xs:string"/>
<xs:element name="Email" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="ListOfContacts">
<xs:complexType>
<xs:sequence>
<xs:element ref="Contact" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:key name="ContactKey">
<xs:selector xpath="Contact"/>
<xs:field xpath="Name"/>
</xs:key>
</xs:element>
Cheers, /Eddie
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
