tags:

views:

21

answers:

1

i wanna make an attribute of an element to be unique like primary key. how to make it?

+2  A: 

Something like this should work:

<xs:element name="books" maxOccurs="unbounded">
   <xs:complexType>
      <xs:sequence>
         <xs:element name="book" maxOccurs="unbounded">
            <xs:complexType>
               <xs:attribute name="isbn" type="xs:string"/>
            </xs:complexType>
         </xs:element>
      </xs:sequence>
   </xs:complexType>
   <xs:unique name="unique-isbn">
      <xs:selector xpath="book"/>
      <xs:field xpath="@isbn"/>
   </xs:unique>
</xs:element>

Basically, you can define a "uniqueness" constraint using a <xs:unique> element and define what XPath this uniqueness should apply to.

See W3Schools' entry on <xs:unique> for more info.

marc_s