xsdata.formats.dataclass.parsers.handlers package

Submodules

Module contents

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

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

Content handler based on lxml iterparse api.

Parameters
parse(source)[source]

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

The xml parser will ignore comments, recover from errors. The parser will parse the whole document and then walk down the tree if the process xinclude is enabled.

Parameters

source (Any) –

Return type

Any

process_context(context)[source]

Iterate context and push the events to main parser.

Parameters

context (Iterable) –

Return type

Any

clazz: Type
parser: xsdata.formats.dataclass.parsers.mixins.PushParser
queue: List
objects: List
class xsdata.formats.dataclass.parsers.handlers.LxmlSaxHandler(clazz, parser, queue=<factory>, objects=<factory>, data_frames=<factory>, flush_next=None)[source]

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

Content handler based on lxml target api.

Parameters
  • data_frames (List) – Cache for text/tail element content

  • flush_next (Optional[str]) – Next element name to flush

  • clazz (Type) –

  • parser (PushParser) –

  • queue (List) –

  • objects (List) –

data_frames: List
flush_next: Optional[str] = None
parse(source)[source]

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

The xml parser will ignore comments, recover from errors and clean duplicate namespace prefixes.

Parameters

source (Any) –

Return type

Any

start(tag, attrib, ns_map)[source]

Start element notification receiver.

The receiver will flush any previous active element, append a new data frame to collect data content for the next active element and notify the main parser to prepare for next binding instruction.

Parameters
end(tag)[source]

End element notification receiver.

The receiver will flush any previous active element and set the next element to be flushed.

Parameters

tag (str) –

close()[source]

Close document notification receiver.

The receiver will flush any previous active element and return the first item in the objects stack.

Return type

Any

flush()[source]

Flush element notification receiver.

The receiver will check if there is an active element present, collect and join the data frames for text/tail content and notify the main parser to finish the binding process for the element.

data(data)[source]

Data notification receiver.

The receiver will append the given data content in the current data frame either in the text position 0 or in the tail position 1 whether the element has ended or not.

Parameters

data (str) –

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

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

Content handler based on xml.ElementTree iterparse api.

Parameters
ns_map: Dict
parse(source)[source]

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

Raises

XmlHandlerError – If process xinclude config is enabled.

Parameters

source (Any) –

Return type

Any

process_context(context)[source]

Iterate context and push the events to main parser.

Parameters

context (Iterable) –

Return type

Any

class xsdata.formats.dataclass.parsers.handlers.XmlSaxHandler(clazz, parser, queue=<factory>, objects=<factory>, data_frames=<factory>, flush_next=None, ns_map=<factory>)[source]

Bases: xsdata.formats.dataclass.parsers.handlers.lxml.LxmlSaxHandler, xml.sax.handler.ContentHandler

Xml sax content handler.

Parameters
ns_map: Dict
parse(source)[source]

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

Raises

XmlHandlerError – If process xinclude config is enabled.

Parameters

source (Any) –

Return type

Any

startElementNS(name, qname, attrs)[source]

Start element notification receiver.

The receiver will flush any previous active element, append a new data frame to collect data content for the next active element and notify the main parser to prepare for next binding instruction.

Converts name and attribute keys to fully qualified tags to respect the main parser api, eg (foo, bar) -> {foo}bar

Parameters
endElementNS(name, qname)[source]

End element notification receiver.

The receiver will flush any previous active element and set the next element to be flushed.

Converts name and attribute keys to fully qualified tags to respect the main parser api, eg (foo, bar) -> {foo}bar

Parameters
characters(content)[source]

Proxy for the data notification receiver.

Parameters

content (str) –

startPrefixMapping(prefix, uri)[source]

Start element prefix-URI namespace mapping.

Parameters
  • prefix (str) –

  • uri (str) –