xsdata.formats.dataclass.parsers package

Subpackages

Submodules

Module contents

class xsdata.formats.dataclass.parsers.JsonParser(context=<factory>)[source]

Bases: xsdata.formats.bindings.AbstractParser

Json parsing and binding for dataclasses.

Parameters

context (XmlContext) – Model metadata builder

context: xsdata.formats.dataclass.context.XmlContext
from_path(path, clazz=None)[source]

Parse the input file path and return the resulting object tree.

Parameters
Return type

~T

parse(source, clazz=None)[source]

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

Parameters
Return type

~T

bind_value(var, value)[source]

Bind value according to the class var.

Parameters
Return type

Any

bind_dataclass(data, clazz)[source]

Recursively build the given model from the input dict data.

Parameters
Return type

~T

bind_dataclass_union(value, var)[source]

Bind data to all possible models and return the best candidate.

Parameters
Return type

Any

bind_wildcard(value)[source]

Bind data to a wildcard model.

Parameters

value (Any) –

Return type

Any

bind_choice(value, var)[source]

Bind data to one of the choice models.

Parameters
Return type

Any

bind_choice_simple(value, var)[source]

Bind data to one of the simple choice types and return the first that succeeds.

Parameters
Return type

Any

bind_choice_generic(value, var)[source]

Bind data to a either a derived or a user derived model.

Parameters
Return type

Any

bind_choice_dataclass(value, var)[source]

Bind data to the best matching choice model.

Parameters
Return type

Any

classmethod parse_value(value, var)[source]

Convert any value to one of the given var types.

Parameters
Return type

Any

class xsdata.formats.dataclass.parsers.XmlParser(config=<factory>, context=<factory>, handler=<class 'xsdata.formats.dataclass.parsers.handlers.lxml.LxmlEventHandler'>)[source]

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

Bind xml nodes to dataclasses with event hooks.

Parameters
handler

alias of xsdata.formats.dataclass.parsers.handlers.lxml.LxmlEventHandler

emit_cache: Dict
start(clazz, queue, objects, qname, attrs, ns_map)[source]

Queue the next xml node for parsing.

Emit a start event with the current element qualified name and attributes.

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

Parse the last xml node and bind any intermediate objects.

Emit an end event with the result object if any.

Return type

Any

Returns

The result of the binding process.

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) –