Chapter 17: Identity constraints

Example 17-10 Illegal attempt to apply default namespace to XPath

<!-- SKIPTEST -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://datypic.com/prod" targetNamespace="http://datypic.com/prod">
  <xs:element name="catalog" type="CatalogType">
    <xs:unique name="dateAndProdNumKey">
      <xs:selector xpath="department/product" />
      <xs:field xpath="number" />
      <xs:field xpath="@effDate" />
    </xs:unique>
  </xs:element>
  <xs:element name="department" type="DepartmentType" />
  <xs:element name="product" type="ProductType" />
  <xs:element name="number" type="xs:integer" />
</xs:schema>

Warning

Unsupported feature!

Example 17-11 Using xpathDefaultNamespace

<!-- SKIPTEST -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://datypic.com/prod" targetNamespace="http://datypic.com/prod" xpathDefaultNamespace="http://datypic.com/prod">
  <xs:element name="catalog" type="CatalogType">
    <xs:unique name="dateAndProdNumKey">
      <xs:selector xpath="department/product" />
      <xs:field xpath="number" />
      <xs:field xpath="@effDate" />
    </xs:unique>
  </xs:element>
  <xs:element name="department" type="DepartmentType" />
  <xs:element name="product" type="ProductType" />
  <xs:element name="number" type="xs:integer" />
</xs:schema>

Warning

Unsupported feature!

Example 17-12 Referencing an identity constraint

<!-- SKIPTEST -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://datypic.com/prod" targetNamespace="http://datypic.com/prod" xpathDefaultNamespace="http://datypic.com/prod">
  <xs:element name="catalog" type="CatalogType">
    <xs:unique name="dateAndProdNumKey">
      <xs:selector xpath="department/product" />
      <xs:field xpath="number" />
      <xs:field xpath="@effDate" />
    </xs:unique>
  </xs:element>
  <xs:element name="discontinuedProductList" type="CatalogType">
    <xs:unique ref="dateAndProdNumKey" />
  </xs:element>
</xs:schema>

Warning

Unsupported feature!

Example 17-13 Referencing an identity constraint in a restriction

<!-- SKIPTEST -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://datypic.com/prod" xmlns="http://datypic.com/prod" xpathDefaultNamespace="http://datypic.com/prod">
  <xs:complexType name="CatalogListType">
    <xs:sequence>
      <xs:element name="catalog" type="CatalogType" maxOccurs="unbounded">
        <xs:unique name="dateAndProdNumKey">
          <xs:selector xpath="department/product" />
          <xs:field xpath="number" />
          <xs:field xpath="@effDate" />
        </xs:unique>
      </xs:element>
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="RestrictedCatalogListType">
    <xs:complexContent>
      <xs:restriction base="CatalogListType">
        <xs:sequence>
          <xs:element name="catalog" type="CatalogType" maxOccurs="1">
            <xs:unique ref="dateAndProdNumKey" />
          </xs:element>
        </xs:sequence>
      </xs:restriction>
    </xs:complexContent>
  </xs:complexType>
</xs:schema>

Warning

Unsupported feature!

Example 17-2 A uniqueness constraint

<!-- SKIPTEST -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="catalog" type="CatalogType">
    <xs:unique name="prodNumKey">
      <xs:selector xpath="*/product" />
      <xs:field xpath="number" />
    </xs:unique>
  </xs:element>
</xs:schema>

Warning

Unsupported feature!

Example 17-4 Constraining uniqueness of two combined fields

<!-- SKIPTEST -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="catalog" type="CatalogType">
    <xs:unique name="dateAndProdNumKey">
      <xs:selector xpath="department/product" />
      <xs:field xpath="number" />
      <xs:field xpath="@effDate" />
    </xs:unique>
  </xs:element>
</xs:schema>

Warning

Unsupported feature!

Example 17-5 Defining a key on product number

<!-- SKIPTEST -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="catalog" type="CatalogType">
    <xs:key name="prodNumKey">
      <xs:selector xpath="*/product" />
      <xs:field xpath="number" />
    </xs:key>
  </xs:element>
</xs:schema>

Warning

Unsupported feature!

Example 17-7 Defining a key reference on product number

<!-- SKIPTEST -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="order" type="OrderType">
    <xs:keyref name="prodNumKeyRef" refer="prodNumKey">
      <xs:selector xpath="items/*" />
      <xs:field xpath="@number" />
    </xs:keyref>
    <xs:key name="prodNumKey">
      <xs:selector xpath=".//product" />
      <xs:field xpath="number" />
    </xs:key>
  </xs:element>
</xs:schema>

Warning

Unsupported feature!

Example 17-8 Illegal uniqueness constraint

<!-- SKIPTEST -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="catalog" type="CatalogType">
    <xs:unique name="prodNumKey">
      <xs:selector xpath="department" />
      <xs:field xpath="product/number" />
    </xs:unique>
  </xs:element>
</xs:schema>

Warning

Unsupported feature!

Example 17-9 Prefixing names in the XPath expression

<!-- SKIPTEST -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:prod="http://datypic.com/prod" targetNamespace="http://datypic.com/prod">
  <xs:element name="catalog" type="prod:CatalogType">
    <xs:unique name="dateAndProdNumKey">
      <xs:selector xpath="prod:department/prod:product" />
      <xs:field xpath="prod:number" />
      <xs:field xpath="@effDate" />
    </xs:unique>
  </xs:element>
  <xs:element name="department" type="prod:DepartmentType" />
  <xs:element name="product" type="prod:ProductType" />
  <xs:element name="number" type="xs:integer" />
</xs:schema>

Warning

Unsupported feature!

Samples Source

Definitive XML Schema by Priscilla Walmsley (c) 2012 Prentice Hall PTR