The key Element
The key identity constraint assures that each key sequencethe set of values specified by the XPath expressions of the nested field elementsis unique. A key sequence is unique if no two key sequences have "equal" values for all keys. Unlike the unique element, a key sequence must exist for each node in the target node set. The key identity constraint is appropriate, for example, for required elements or attributes.
A catalog part number, where every catalog entry must have a part number, is a great example of using a key:
<xsd:key name="partNumberKey"> <xsd:annotation> <xsd:documentation xml:lang="en"> The part number uniquely identifies each orderable item. </xsd:documentation> </xsd:annotation> <xsd:selector xpath="catalog/*"/> <xsd:field xpath="partNumber"/> </xsd:key>