xsdata.formats.dataclass.parsers.nodes module

class xsdata.formats.dataclass.parsers.nodes.XmlNode(position)[source]

Bases: object

A generic interface for xml nodes that need to implement the two public methods to be used in an event based parser with start/end element events. The parser needs to maintain a queue for these nodes and a list of objects that these nodes return.

Parameters

position (int) – The current objects size, when the node is created.

position: int
next_node(element, position, ctx)[source]

Initialize the next node to be queued, when a new xml element starts.

This entry point is responsible to create the next node type with all the necessary information on how to bind the incoming input data.

Parameters
Return type

XmlNode

parse_element(element, objects)[source]

Parse the current element bind child objects and return the result.

This entry point is called when an xml element ends and is responsible to parse the current element attributes/text, bind any children objects and initialize a new object.

Return type

Tuple

Returns

A tuple of the object’s qualified name and the new object.

Parameters
  • element (Element) –

  • objects (List[Any]) –

class xsdata.formats.dataclass.parsers.nodes.ElementNode(position, meta, config)[source]

Bases: xsdata.formats.dataclass.parsers.nodes.XmlNode

Element type node is equivalent to xml elements and is used to bind user defined dataclasses.

Parameters
  • meta (XmlMeta) – xml metadata of a dataclass model.

  • config (ParserConfig) – Parser config instance passed down from the root node.

  • position (int) –

meta: XmlMeta
config: ParserConfig
parse_element(element, objects)[source]

Parse the given element attributes/text, find all child objects and mixed content and initialize a new dataclass instance.

Return type

Tuple

Returns

A tuple of the object’s qualified name and the new object.

Parameters
  • element (Element) –

  • objects (List[Any]) –

next_node(element, position, ctx)[source]

Initialize the next node to be queued for the given starting element.

Search by the given element tag for a matching variable and create the next node by the variable type.

Return type

XmlNode

Returns

The next node to be queued.

Raises

XmlContextError if the element is unknown and parser config is strict.

Parameters
class xsdata.formats.dataclass.parsers.nodes.RootNode(position, meta, config)[source]

Bases: xsdata.formats.dataclass.parsers.nodes.ElementNode

Parameters
next_node(element, position, ctx)[source]

Override parent to return itself if the current element is root.

Parameters
Return type

XmlNode

meta
config
class xsdata.formats.dataclass.parsers.nodes.WildcardNode(position, qname)[source]

Bases: xsdata.formats.dataclass.parsers.nodes.XmlNode

Wildcard nodes are used for extensible elements that can hold any attribute and content and don’t have a specific dataclass or primitive type.

Notes:

In the future this node should check all known user defined models in the target namespace and use that instead of the generic.

Parameters
  • qname (QName) – xml element tag

  • position (int) –

qname: QName
parse_element(element, objects)[source]

Parse the given element attributes/text/tail, find all child objects and mixed content and initialize a new generic element instance.

Return type

Tuple

Returns

A tuple of the object’s qualified name and a new xsdata.formats.dataclass.models.generics.AnyElement instance.

Parameters
  • element (Element) –

  • objects (List[Any]) –

next_node(element, position, ctx)[source]

Initialize the next wildcard node to be queued for the given starting element.

Notes: Wildcard nodes can only queue other wildcard nodes.

Parameters
Return type

XmlNode

class xsdata.formats.dataclass.parsers.nodes.PrimitiveNode(position, var)[source]

Bases: xsdata.formats.dataclass.parsers.nodes.XmlNode

Parameters
var: XmlVar
parse_element(element, objects)[source]

Parse the given element text according to the node possible types.

Return type

Tuple

Returns

A tuple of the object’s qualified name and the new object.

Parameters
  • element (Element) –

  • objects (List) –

next_node(element, position, ctx)[source]

Initialize the next node to be queued, when a new xml element starts.

This entry point is responsible to create the next node type with all the necessary information on how to bind the incoming input data.

Parameters
Return type

XmlNode

class xsdata.formats.dataclass.parsers.nodes.SkipNode(position)[source]

Bases: xsdata.formats.dataclass.parsers.nodes.XmlNode

This node is used by the parser to skip unknown elements and their children.

The result of the next_node is always another SkipNode and the result of parse_element is always a tuple of None values.

Parameters

position (int) –

next_node(element, position, ctx)[source]

Initialize the next node to be queued, when a new xml element starts.

This entry point is responsible to create the next node type with all the necessary information on how to bind the incoming input data.

Parameters
Return type

XmlNode

parse_element(element, objects)[source]

Parse the current element bind child objects and return the result.

This entry point is called when an xml element ends and is responsible to parse the current element attributes/text, bind any children objects and initialize a new object.

Return type

Tuple

Returns

A tuple of the object’s qualified name and the new object.

Parameters
  • element (Element) –

  • objects (List[Any]) –

position