xsdata.formats.dataclass.parsers.xml module

class xsdata.formats.dataclass.parsers.xml.XmlParser(context=<factory>, event_names=<factory>, config=<factory>)[source]

Bases: xsdata.formats.bindings.AbstractParser

Xml parsing and binding for dataclasses.

Parameters
  • namespaces – Store the prefix/namespace as they are parsed.

  • context (XmlContext) – Model metadata builder

  • event_names (Dict) – Cache for event names for each element

  • config (ParserConfig) – Parser configuration

namespaces: Namespaces
context: XmlContext
event_names: Dict
config: ParserConfig
parse(source, clazz)[source]

Parse the XML input stream and return the resulting object tree.

Parameters
  • source (BytesIO) –

  • clazz (Type[~T]) –

Return type

~T

parse_context(context, clazz)[source]

Dispatch elements to handlers as they arrive and are fully parsed.

Raises

ParserError – When the requested type doesn’t match the result object

Parameters
  • context (iterparse) –

  • clazz (Type[~T]) –

Return type

~T

add_namespace(namespace)[source]

Add the given namespace in the registry.

Parameters

namespace (Tuple) –

queue(element, queue, objects)[source]

Queue the next xml node for parsing based on the given element qualified name.

Parameters
dequeue(element, queue, objects)[source]

Use the last xml node to parse the given element and bind any child objects.

Return type

Any

Returns

Any: A dataclass instance or a python primitive value or None

Parameters
emit_event(event, name, **kwargs)[source]

Call if exist the parser’s hook for the given element and event.

Parameters
  • event (str) –

  • name (str) –

  • kwargs (Any) –