Home > Articles > Web Services > XML

  • Print
  • + Share This
From the author of

The unique Element

The unique 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 key element, the key sequence does not have to exist for each node in the target node set. The unique identity constraint is appropriate, for example, for optional elements or attributes.

In practice, this identity constraint is slightly more difficult to explain. The next example specifies that if an order has a shipping identifier attribute, that shipping identifier must be unique:

<xsd:unique name="orderShippedUnique">
  <xsd:annotation>
    <xsd:documentation xml:lang="en">
      The customerID uniquely identifies
      each customer.
    </xsd:documentation>
  </xsd:annotation>
  <xsd:selector xpath="order"/>
  <xsd:field xpath="@shipmentID"/>
</xsd:unique>
  • + Share This
  • 🔖 Save To Your Account