Chapter 11¶
Built-in simple types¶
Example 11-1 Extensible mixed content¶
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="TextType" mixed="true">
<xs:sequence>
<xs:any namespace="##any" processContents="lax" minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
<xs:attribute ref="xml:lang" />
</xs:complexType>
</xs:schema>
from dataclasses import dataclass, field
from typing import List, Optional
@dataclass
class TextType:
"""
:ivar any_element:
:ivar lang:
"""
any_element: List[object] = field(
default_factory=list,
metadata=dict(
type="Wildcard",
namespace="##any",
min_occurs=0,
max_occurs=9223372036854775807
)
)
lang: Optional[str] = field(
default=None,
metadata=dict(
type="Attribute",
namespace="http://www.w3.org/XML/1998/namespace"
)
)
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(
type="Attribute",
required=True
)
)
@dataclass
class Quote:
"""
:ivar ref:
"""
class Meta:
name = "quote"
ref: Optional[str] = field(
default=None,
metadata=dict(
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(
type="Attribute",
required=True
)
)
@dataclass
class Quote:
"""
:ivar refs:
"""
class Meta:
name = "quote"
refs: Optional[str] = field(
default=None,
metadata=dict(
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(
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(
type="Attribute"
)
)
Samples Source
Definitive XML Schema by Priscilla Walmsley (c) 2012 Prentice Hall PTR