xsdata.formats.dataclass.models.elements module

class xsdata.formats.dataclass.models.elements.XmlVar(name, qname, init=True, mixed=False, tokens=False, derived=False, nillable=False, dataclass=False, sequential=False, list_element=False, default=None, choices=<factory>, types=<factory>, namespaces=<factory>)[source]

Bases: object

Dataclass field bind metadata.

Parameters
  • name (str) – Field name.

  • qname (str) – The namespace qualified local name.

  • init (bool) – Field is present in the constructor parameters.

  • mixed (bool) – Field supports mixed content.

  • tokens (bool) – Use a list to map simple values.

  • derived (bool) – Use derived elements to bind data.

  • nillable (bool) – Allow empty content elements rendering.

  • dataclass (bool) – Specify whether the field type is a dataclass.

  • sequential (bool) – Switch to sequential rendering with other sequential siblings

  • list_element (bool) – Specify whether the field represents a list of elements

  • default (Optional[Any]) – Field default value or factory

  • choices (List[XmlVar]) – Field compound element choices.

  • types (List[Type]) – Field simple types.

  • namespaces (List[str]) – Field list of the all the possible namespaces.

name: str
qname: str
init: bool = True
mixed: bool = False
tokens: bool = False
derived: bool = False
nillable: bool = False
dataclass: bool = False
sequential: bool = False
list_element: bool = False
default: Any = None
choices: List[xsdata.formats.dataclass.models.elements.XmlVar]
types: List[Type]
namespaces: List[str]
property clazz

Return the first type if field is bound to a dataclass.

Return type

Optional[Type]

property is_any_type

Return whether the field type is xs:anyType.

Return type

bool

property is_attribute

Return whether the field is derived from xs:attribute.

Return type

bool

property is_attributes

Return whether the field is derived from xs:anyAttributes.

Return type

bool

property is_element

Return whether the field is derived from xs:element.

Return type

bool

property is_elements

Return whether the field is a compound of other elements.

Return type

bool

property is_list

Return whether the field is a list of elements.

Return type

bool

property is_mixed_content

Return whether the field is a mixed content list of of elements.

Return type

bool

property is_clazz_union
Return type

bool

property is_text

Return whether the field is a text element.

Return type

bool

property is_wildcard

Return whether the field is a text element.

Return type

bool

property local_name

The element local name.

Return type

str

matches(qname)[source]

Match the field qualified local name to the given qname.

Return True automatically if the local name is a wildcard.

Parameters

qname (str) –

Return type

bool

find_choice(qname)[source]

Match and return a choice field by its qualified name.

Parameters

qname (str) –

Return type

Optional[XmlVar]

find_value_choice(value)[source]

Match and return a choice field that matches the given value.

Parameters

value (Any) –

Return type

Optional[XmlVar]

class xsdata.formats.dataclass.models.elements.XmlElement(name, qname, init=True, mixed=False, tokens=False, derived=False, nillable=False, dataclass=False, sequential=False, list_element=False, default=None, choices=<factory>, types=<factory>, namespaces=<factory>)[source]

Bases: xsdata.formats.dataclass.models.elements.XmlVar

Dataclass field bind metadata for xml elements.

Parameters
property is_element

Return whether the field is derived from xs:element.

Return type

bool

property is_any_type

Return whether the field type is xs:anyType.

Return type

bool

name: str
qname: str
choices: List[xsdata.formats.dataclass.models.elements.XmlVar]
types: List[Type]
namespaces: List[str]
class xsdata.formats.dataclass.models.elements.XmlElements(name, qname, init=True, mixed=False, tokens=False, derived=False, nillable=False, dataclass=False, sequential=False, list_element=False, default=None, choices=<factory>, types=<factory>, namespaces=<factory>)[source]

Bases: xsdata.formats.dataclass.models.elements.XmlVar

Dataclass field bind metadata for compound list of xml elements.

Parameters
property is_elements

Return whether the field is a compound of other elements.

Return type

bool

matches(qname)[source]

Return whether a choice element matches the given qualified name.

Parameters

qname (str) –

Return type

bool

find_choice(qname)[source]

Match and return a choice field by its qualified name.

Parameters

qname (str) –

Return type

Optional[XmlVar]

find_value_choice(value)[source]

Match and return a choice field that matches the given value.

Parameters

value (Any) –

Return type

Optional[XmlVar]

name: str
qname: str
choices: List[xsdata.formats.dataclass.models.elements.XmlVar]
types: List[Type]
namespaces: List[str]
class xsdata.formats.dataclass.models.elements.XmlWildcard(name, qname, init=True, mixed=False, tokens=False, derived=False, nillable=False, dataclass=False, sequential=False, list_element=False, default=None, choices=<factory>, types=<factory>, namespaces=<factory>)[source]

Bases: xsdata.formats.dataclass.models.elements.XmlVar

Dataclass field bind metadata for xml wildcard elements.

Parameters
property is_mixed_content

Return whether the field is a mixed content list of of elements.

Return type

bool

property is_wildcard

Return whether the field is a text element.

Return type

bool

matches(qname)[source]

Match the given qname to the wildcard allowed namespaces.

Parameters

qname (str) –

Return type

bool

static match_namespace(source, cmp)[source]
Parameters
Return type

bool

name: str
qname: str
choices: List[xsdata.formats.dataclass.models.elements.XmlVar]
types: List[Type]
namespaces: List[str]
class xsdata.formats.dataclass.models.elements.XmlAttribute(name, qname, init=True, mixed=False, tokens=False, derived=False, nillable=False, dataclass=False, sequential=False, list_element=False, default=None, choices=<factory>, types=<factory>, namespaces=<factory>)[source]

Bases: xsdata.formats.dataclass.models.elements.XmlVar

Dataclass field bind metadata for xml attributes.

Parameters
property is_attribute

Return whether the field is derived from xs:attribute.

Return type

bool

name: str
qname: str
choices: List[xsdata.formats.dataclass.models.elements.XmlVar]
types: List[Type]
namespaces: List[str]
class xsdata.formats.dataclass.models.elements.XmlAttributes(name, qname, init=True, mixed=False, tokens=False, derived=False, nillable=False, dataclass=False, sequential=False, list_element=False, default=None, choices=<factory>, types=<factory>, namespaces=<factory>)[source]

Bases: xsdata.formats.dataclass.models.elements.XmlVar

Dataclass field bind metadata for xml wildcard attributes.

Parameters
property is_attributes

Return whether the field is derived from xs:anyAttributes.

Return type

bool

name: str
qname: str
choices: List[xsdata.formats.dataclass.models.elements.XmlVar]
types: List[Type]
namespaces: List[str]
class xsdata.formats.dataclass.models.elements.XmlText(name, qname, init=True, mixed=False, tokens=False, derived=False, nillable=False, dataclass=False, sequential=False, list_element=False, default=None, choices=<factory>, types=<factory>, namespaces=<factory>)[source]

Bases: xsdata.formats.dataclass.models.elements.XmlVar

Dataclass field bind metadata for xml text content.

Parameters
property is_text

Return whether the field is a text element.

Return type

bool

name: str
qname: str
choices: List[xsdata.formats.dataclass.models.elements.XmlVar]
types: List[Type]
namespaces: List[str]
class xsdata.formats.dataclass.models.elements.FindMode(value)[source]

Bases: enum.IntEnum

Find switches to be used to find a specific var.

ALL = 1
ATTRIBUTE = 2
ATTRIBUTES = 3
TEXT = 4
WILDCARD = 5
MIXED_CONTENT = 0
NOT_WILDCARD = 6
class xsdata.formats.dataclass.models.elements.XmlMeta(clazz, qname, source_qname, nillable, vars=<factory>)[source]

Bases: object

Dataclass model bind metadata.

Parameters
  • clazz (Type) – The dataclass type

  • qname (str) – The namespace qualified name.

  • source_qname (str) – The source namespace qualified name.

  • nillable (bool) – Specifies whether an explicit empty value can be assigned.

  • vars (List[XmlVar]) – The list of field metadata

clazz: Type
qname: str
source_qname: str
nillable: bool
vars: List[xsdata.formats.dataclass.models.elements.XmlVar]
cache: Dict
property namespace
Return type

Optional[str]

has_var(qname='*', mode=<FindMode.ALL: 1>)[source]
Parameters
Return type

bool

find_var(qname='*', mode=<FindMode.ALL: 1>)[source]

Find and cache a field by it’s qualified name and the specified mode.

Parameters
Return type

Optional[XmlVar]