defxmlschema/chapter11

Example 11-5 Using IDREF

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="quote">
    <xs:complexType>
      <!-- content model -->
      <xs:attribute name="ref" type="xs:IDREF" />
    </xs:complexType>
  </xs:element>
  <xs:element name="footnote">
    <xs:complexType>
      <!-- content model -->
      <xs:attribute name="id" type="xs:ID" use="required" />
    </xs:complexType>
  </xs:element>
</xs:schema>
from dataclasses import dataclass, field
from typing import Optional


@dataclass
class Footnote:
    """
    :ivar id:
    """
    class Meta:
        name = "footnote"

    id: Optional[str] = field(
        default=None,
        metadata=dict(
            name="id",
            type="Attribute",
            required=True
        )
    )


@dataclass
class Quote:
    """
    :ivar ref:
    """
    class Meta:
        name = "quote"

    ref: Optional[str] = field(
        default=None,
        metadata=dict(
            name="ref",
            type="Attribute"
        )
    )

Example 11-6 Using IDREFS

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="quote">
    <xs:complexType>
      <!-- content model -->
      <xs:attribute name="refs" type="xs:IDREFS" />
    </xs:complexType>
  </xs:element>
  <xs:element name="footnote">
    <xs:complexType>
      <!-- content model -->
      <xs:attribute name="id" type="xs:ID" use="required" />
    </xs:complexType>
  </xs:element>
</xs:schema>
from dataclasses import dataclass, field
from typing import Optional


@dataclass
class Footnote:
    """
    :ivar id:
    """
    class Meta:
        name = "footnote"

    id: Optional[str] = field(
        default=None,
        metadata=dict(
            name="id",
            type="Attribute",
            required=True
        )
    )


@dataclass
class Quote:
    """
    :ivar refs:
    """
    class Meta:
        name = "quote"

    refs: Optional[str] = field(
        default=None,
        metadata=dict(
            name="refs",
            type="Attribute"
        )
    )

Example 11-7 Using an unparsed entity

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="picture">
    <xs:complexType>
      <xs:attribute name="location" type="xs:ENTITY" />
    </xs:complexType>
  </xs:element>
</xs:schema>
from dataclasses import dataclass, field
from typing import Optional


@dataclass
class Picture:
    """
    :ivar location:
    """
    class Meta:
        name = "picture"

    location: Optional[int] = field(
        default=None,
        metadata=dict(
            name="location",
            type="Attribute"
        )
    )

Example 11-8 Using ENTITIES

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="pictures">
    <xs:complexType>
      <xs:attribute name="location" type="xs:ENTITIES" />
    </xs:complexType>
  </xs:element>
</xs:schema>
from dataclasses import dataclass, field
from typing import Optional


@dataclass
class Pictures:
    """
    :ivar location:
    """
    class Meta:
        name = "pictures"

    location: Optional[int] = field(
        default=None,
        metadata=dict(
            name="location",
            type="Attribute"
        )
    )

Samples Source

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