Home > Articles > Web Services > XML

  • Print
  • + Share This
From the author of

The key Element

The key identity constraint assures that each key sequence—the set of values specified by the XPath expressions of the nested field elements—is 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>
  • + Share This
  • 🔖 Save To Your Account