xsdata.formats.dataclass.parsers.mixins module

class xsdata.formats.dataclass.parsers.mixins.PushParser[source]

Bases: xsdata.formats.bindings.AbstractParser

A generic interface for event based content handlers like sax.

Parameters

config – Parser configuration.

config: xsdata.formats.dataclass.parsers.config.ParserConfig
abstract start(clazz, queue, objects, qname, attrs, ns_map)[source]

Queue the next xml node for parsing.

Parameters
abstract end(queue, objects, qname, text, tail)[source]

Parse the last xml node and bind any intermediate objects.

Return type

Any

Returns

The result of the binding process.

Parameters
abstract start_prefix_mapping(prefix, uri)[source]

Add the given namespace in the registry.

Parameters
class xsdata.formats.dataclass.parsers.mixins.XmlNode[source]

Bases: abc.ABC

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.

abstract child(qname, attrs, ns_map, position)[source]

Initialize the next child 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
  • qname (str) –

  • attrs (Dict) –

  • ns_map (Dict) –

  • position (int) –

Return type

XmlNode

abstract bind(qname, text, tail, 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

bool

Returns

Whether or not anything was appended in the objects list.

Parameters
class xsdata.formats.dataclass.parsers.mixins.XmlHandler(clazz, parser, queue=<factory>, objects=<factory>)[source]

Bases: object

Xml content handler interface.

Parameters
  • clazz (Type) – The Dataclass model to bind the xml document data.

  • parser (PushParser) – The parser instance to feed events.

  • queue (List) – The queue list of xml nodes.

  • objects (List) – Temporary storage for intermediate objects, eg [(qname, object)]

clazz: Type
parser: xsdata.formats.dataclass.parsers.mixins.PushParser
queue: List
objects: List
parse(source)[source]

Parse an XML document from a system identifier or an InputSource.

Parameters

source (Any) –

Return type

Any

start_ns_bulk(ns_map)[source]

Bulk start-ns event handler that returns a normalized copy of the prefix-URI mapping that also includes the parent mapping.

Parameters

ns_map (Dict) –

Return type

Dict

class xsdata.formats.dataclass.parsers.mixins.EventsHandler(clazz, parser, queue=<factory>, objects=<factory>)[source]

Bases: xsdata.formats.dataclass.parsers.mixins.XmlHandler

Content handler based on pre-recorded events.

Parameters
parse(source)[source]

Forward the pre-recorded events to the main parser.

Parameters

source (List[Tuple]) –

Return type

Any

clazz: Type
parser: xsdata.formats.dataclass.parsers.mixins.PushParser
queue: List
objects: List