ElementNode#

class xsdata.formats.dataclass.parsers.nodes.ElementNode(meta, attrs, ns_map, config, context, position, mixed=False, derived_factory=None, xsi_type=None, xsi_nil=None)[source]#

XmlNode for complex elements.

Parameters:
  • meta (XmlMeta) – The class binding metadata instance

  • attrs (Dict) – The element attributes

  • ns_map (Dict) – The element namespace prefix-URI map

  • config (ParserConfig) – The parser config instance

  • context (XmlContext) – The models context instance

  • position (int) – The current objects length, everything after this position are considered children of this node.

  • mixed (bool) – Specifies whether this node supports mixed content.

  • derived_factory (Optional[Type]) – Derived element factory

  • xsi_type (Optional[str]) – The xml type substitution

  • xsi_nil (Optional[bool]) – Specifies whether element has the xsi:nil attribute

assigned#

A set to store the processed sub-nodes

tail_processed#

Whether the tail process is consumed

bind(qname, text, tail, objects)[source]#

Bind the parsed data into an object for the ending element.

This entry point is called when a xml element ends and is responsible to parse the current element attributes/text, bind any children objects and initialize new object.

Parameters:
  • qname (str) – The element qualified name

  • text (Optional[str]) – The element text content

  • tail (Optional[str]) – The element tail content

  • objects (List[Any]) – The list of intermediate parsed objects

Return type:

bool

Returns:

Whether the binding process was successful or not.

bind_content(params, text, tail, objects)[source]#

Parse the text and tail content.

Parameters:
  • params (Dict) – The class parameters

  • text (Optional[str]) – The element text content

  • tail (Optional[str]) – The element tail content

  • objects (List[Any]) – The list of intermediate parsed objects

bind_attrs(params)[source]#

Parse the element attributes.

Scenarios:
  • Each attribute matches a class field

  • Class has a wildcard field that sucks everything else

Parameters:

params (Dict[str, Any]) – The class parameters

Raises:

ParserError – If the document contains an unknown attribute and the configuration is strict.

bind_attr(params, var, value)[source]#

Parse an element attribute.

Ignores fields with init==false!

Parameters:
  • params (Dict) – The class parameters

  • var (XmlVar) – The xml var instance

  • value (Any) – The attribute value

bind_any_attr(params, var, qname, value)[source]#

Parse an element attribute to a wildcard field.

Parameters:
  • params (Dict) – The class parameters

  • var (XmlVar) – The xml var instance

  • qname (str) – The attribute namespace qualified name

  • value (Any) – The attribute value

bind_objects(params, objects)[source]#

Bind children objects.

Emit a warning if an object doesn’t fit in any class parameters.

Parameters:
  • params (Dict) – The class parameters

  • objects (List) – The list of intermediate parsed objects

bind_object(params, qname, value)[source]#

Bind a child object.

Parameters:
  • params (Dict) – The class parameters

  • qname (str) – The qualified name of the element

  • value (Any) – The parsed object

Return type:

bool

Returns:

Whether the parsed object can fit in one of class parameters or not.

classmethod bind_var(params, var, value)[source]#

Bind a child object to an element field.

Parameters:
  • params (Dict) – The class parameters

  • var (XmlVar) – The matched xml var instance

  • value (Any) – The parsed object

Return type:

bool

Returns:

Whether the parsed object can fit in one of class parameters or not.

bind_wild_var(params, var, qname, value)[source]#

Bind a child object to a wildcard field.

The wildcard might support one or more values. If it supports only one the values are nested under a parent generic element instance.

Parameters:
  • params (Dict) – The class parameters

  • var (XmlVar) – The wildcard var instance

  • qname (str) – The qualified name of the element

  • value (Any) – The parsed value

Return type:

bool

Returns:

Always true, since wildcard fields can absorb any value.

bind_mixed_objects(params, var, objects)[source]#

Bind children objects to a mixed content wildcard field.

Parameters:
  • params (Dict) – The class parameters

  • var (XmlVar) – The wildcard var instance

  • objects (List) – The list of intermediate parsed objects

prepare_generic_value(qname, value)[source]#

Wrap primitive text nodes in a generic element.

Parameters:
  • qname (Optional[str]) – The qualified name of the element

  • value (Any) – The parsed object

Return type:

Any

Returns:

The original parsed value if it’s a data class, or the wrapped primitive value in a generic element.

bind_text(params, text)[source]#

Bind the element text content.

Parameters:
  • params (Dict) – The class parameters

  • text (Optional[str]) – The element text content

Return type:

bool

Returns:

Whether the text content can fit in one of class parameters or not.

bind_wild_text(params, var, text, tail)[source]#

Bind the element text and tail content to a wildcard field.

If the field is a list, prepend the text and append the tail content. Otherwise, build a generic element with the text/tail content and any attributes. If the field is already occupied, then this means the current node is a child, and we need to nested them.

Parameters:
  • params (Dict) – The class parameters

  • var (XmlVar) – The wildcard var instance

  • text (Optional[str]) – The element text content

  • tail (Optional[str]) – The element text content

Return type:

bool

Returns:

Whether the text content can fit in one of class parameters or not.

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

Initialize the next child node to be queued, when an 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) – The element qualified name

  • attrs (Dict) – The element attributes

  • ns_map (Dict) – The element namespace prefix-URI map

  • position (int) – The current length of the intermediate objects

Raises:

ParserError – If the child element is unknown

Return type:

XmlNode

build_node(qname, var, attrs, ns_map, position)[source]#

Build the next child node based on the xml var instance.

Parameters:
  • qname (str) – The element qualified name

  • var (XmlVar) – The xml var instance

  • attrs (Dict) – The element attributes

  • ns_map (Dict) – The element namespace prefix-URI map

  • position (int) – The current length of the intermediate objects

Return type:

Optional[XmlNode]

Returns:

The next child node instance, or None if nothing matched the starting element.

build_element_node(clazz, derived, nillable, attrs, ns_map, position, derived_factory, xsi_type=None, xsi_nil=None)[source]#

Build the next element child node.

Parameters:
  • clazz (Type) – The target class

  • derived (bool) – Whether derived elements should wrap the parsed object

  • nillable (bool) – Specifies whether nil content is allowed

  • attrs (Dict) – The element attributes

  • ns_map (Dict) – The element namespace prefix-URI map

  • position (int) – The current length of the intermediate objects

  • derived_factory (Type) – The derived factory

  • xsi_type (Optional[str]) – The xml type substitution

  • xsi_nil (Optional[bool]) – Specifies whether the node supports nillable content

Return type:

Optional[ElementNode]

Returns:

The next child element node instance, or None if the clazz doesn’t match the starting element.