Chapter 17: Identity constraints

Example 17-13 Referencing an identity constraint in a restriction

<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:include  schemaLocation="../chapter15/example1515.xsd" />
    <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>
from dataclasses import dataclass, field
from typing import List, Optional
from tests.fixtures.defxmlschema.chapter15.example1515 import (
    CatalogType,
)


@dataclass
class CatalogListType:
    """
    :ivar catalog:
    """
    catalog: List[CatalogType] = field(
        default_factory=list,
        metadata=dict(
            name="catalog",
            type="Element",
            namespace="",
            min_occurs=1,
            max_occurs=9223372036854775807
        )
    )


@dataclass
class RestrictedCatalogListType:
    """
    :ivar catalog:
    """
    catalog: Optional[CatalogType] = field(
        default=None,
        metadata=dict(
            name="catalog",
            type="Element",
            namespace="",
            required=True
        )
    )

Samples Source

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