xsdata.formats.dataclass.parsers.utils module

class xsdata.formats.dataclass.parsers.utils.ParserUtils[source]

Bases: object

classmethod parse_xsi_type(element)[source]

Parse the elements xsi:type attribute if present.

Parameters

element (Element) –

Return type

Optional[QName]

classmethod parse_value(types, value, default=None, ns_map=None, tokens=False)[source]

Convert xml string values to s python primitive type.

Parameters
Return type

Any

classmethod bind_element_children(params, meta, position, objects)[source]

Return a dictionary of qualified object names and their values for the given queue item.

Parameters
classmethod fetch_any_children(position, objects)[source]

Fetch the children of a wildcard node.

Parameters
  • position (int) –

  • objects (List) –

Return type

List[object]

classmethod bind_element_param(params, var, value)[source]

Add the given value to the params dictionary with the var name as key.

Wrap the value to a list if var is a list. If the var name already exists it means we have a name conflict and the parser needs to lookup for any available wildcard fields.

Return type

bool

Returns

Whether the binding process was successful or not.

Parameters
classmethod bind_element_wildcard_param(params, var, qname, value)[source]

Add the given value to the params dictionary with the wildcard var name as key.

If the key is already present wrap the previous value into a generic AnyElement instance. If the previous value is already a generic instance add the current value as a child object.

Parameters
  • params (Dict) –

  • var (XmlVar) –

  • qname (QName) –

  • value (Any) –

classmethod bind_element_wild_text(params, meta, element)[source]

Extract the text and tail content and bind it accordingly in the params dictionary.

  • var is a list prepend the text and append the tail.

  • var is present in the params assign the text and tail to the generic object.

  • Otherwise bind the given element to a new generic object.

Parameters
  • params (Dict) –

  • meta (XmlMeta) –

  • element (Element) –

classmethod element_text_and_tail(element)[source]

Extract the text and tail content if any and return them both.

Parameters

element (Element) –

Return type

Tuple

classmethod parse_any_element(element, qname=True)[source]

Bind the given element content to a new generic object.

Parameters
  • element (Element) –

  • qname (bool) –

Return type

AnyElement

classmethod parse_any_attributes(element)[source]

Extract the given element’s attributes into the dictionary with keys the fully qualified attribute names.

Parameters

element (Element) –

Return type

Dict[QName, Any]

classmethod bind_element_text(params, metadata, element)[source]

Add the given element’s text content if any to the params dictionary with the text var name as key.

Parameters
  • params (Dict) –

  • metadata (XmlMeta) –

  • element (Element) –

classmethod bind_element_attrs(params, metadata, element)[source]

Parse the given element’s attributes and any text content and return a dictionary of field names and values based on the given class metadata.

Parameters
  • params (Dict) –

  • metadata (XmlMeta) –

  • element (Element) –

classmethod find_eligible_wildcard(meta, qname, params)[source]

Last resort lookup for a suitable wildcard var.

Search for a list wildcard or a wildcard that already exists in the params dictionary.

Parameters
  • meta (XmlMeta) –

  • qname (QName) –

  • params (Dict) –

Return type

Optional[XmlVar]