xsdata.formats.dataclass.parsers.nodes module¶
-
class
xsdata.formats.dataclass.parsers.nodes.XmlNode(position)[source]¶ Bases:
objectA 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.
-
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
element (
Element) –position (
int) –ctx (
XmlContext) –
- Return type
-
class
xsdata.formats.dataclass.parsers.nodes.ElementNode(position, meta, config)[source]¶ Bases:
xsdata.formats.dataclass.parsers.nodes.XmlNodeElement 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.
-
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
- Returns
The next node to be queued.
- Raises
XmlContextError if the element is unknown and parser config is strict.
- Parameters
element (
Element) –position (
int) –ctx (
XmlContext) –
-
class
xsdata.formats.dataclass.parsers.nodes.RootNode(position, meta, config)[source]¶ Bases:
xsdata.formats.dataclass.parsers.nodes.ElementNode- Parameters
position (
int) –meta (
XmlMeta) –config (
ParserConfig) –
-
next_node(element, position, ctx)[source]¶ Override parent to return itself if the current element is root.
- Parameters
element (
Element) –position (
int) –ctx (
XmlContext) –
- Return type
-
meta¶
-
config¶
-
class
xsdata.formats.dataclass.parsers.nodes.WildcardNode(position, var)[source]¶ Bases:
xsdata.formats.dataclass.parsers.nodes.XmlNodeWildcard 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.
-
var: XmlVar¶
-
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.
-
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
element (
Element) –position (
int) –ctx (
XmlContext) –
- Return type
-
class
xsdata.formats.dataclass.parsers.nodes.UnionNode(position, var, ctx)[source]¶ Bases:
xsdata.formats.dataclass.parsers.nodes.XmlNodeUnion nodes are used for variables with more than one possible types where at least one of them is a dataclass.
- Parameters
position (
int) –var (
XmlVar) –ctx (
XmlContext) –
-
var: XmlVar¶
-
ctx: XmlContext¶
-
next_node(element, position, ctx)[source]¶ Skip all child nodes as we are going to parse the complete element tree.
- Parameters
element (
Element) –position (
int) –ctx (
XmlContext) –
- Return type
-
parse_element(element, objects)[source]¶ The handler will make multiple tries to bind the given element to one of the available dataclass var types convert it to one of the available primitive types.
The first shoe that fits wins!
-
class
xsdata.formats.dataclass.parsers.nodes.PrimitiveNode(position, var)[source]¶ Bases:
xsdata.formats.dataclass.parsers.nodes.XmlNodeXmlNode for text elements with primitive values eg str, int, float.
-
var: XmlVar¶
-
parse_element(element, objects)[source]¶ Parse the given element text according to the node possible types.
-
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
element (
Element) –position (
int) –ctx (
XmlContext) –
- Return type
-
-
class
xsdata.formats.dataclass.parsers.nodes.SkipNode(position)[source]¶ Bases:
xsdata.formats.dataclass.parsers.nodes.XmlNodeThe skip node should be used when we want to skip parsing child elements.
- Parameters
position (
int) –
-
next_node(element, position, ctx)[source]¶ Skip the current child.
- Parameters
element (
Element) –position (
int) –ctx (
XmlContext) –
- Return type
-
position¶
-
class
xsdata.formats.dataclass.parsers.nodes.NodeParser(config=<factory>, context=<factory>)[source]¶ Bases:
objectXml parsing and binding for dataclasses.
- Parameters
config (
ParserConfig) – Parser configurationcontext (
XmlContext) – Model metadata buildernamespaces – Store the prefix/namespace as they are parsed.
-
config: ParserConfig¶
-
context: XmlContext¶
-
namespaces: Namespaces¶
-
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
- Return type
~T
-
add_namespace(namespace)[source]¶ Add the given namespace in the registry.
- Parameters
namespace (
Tuple) –