xsdata.formats.dataclass.parsers.utils module

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

Bases: object

classmethod parse_xsi_type(attrs, ns_map)[source]

Parse the elements xsi:type attribute if present.

Parameters
Return type

Optional[str]

classmethod parse_value(value, types, 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 bind_mixed_content(params, var, pos, objects)[source]

Return a dictionary of qualified object names and their values for the given mixed content xml var.

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 prepare_generic_value(qname, value)[source]

Prepare parsed value before binding to a wildcard field.

Parameters
Return type

Any

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
classmethod bind_wildcard_element(params, var, txt, tail, attrs, ns_map)[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
classmethod normalize_content(value)[source]

Normalize element text or tail content.

If content is just whitespace return None, otherwise preserve the original content.

Parameters

value (Optional[str]) –

Return type

Optional[str]

classmethod parse_any_attributes(attrs, ns_map)[source]
Parameters
Return type

Dict

classmethod parse_any_attribute(value, ns_map)[source]

Attempt to parse any attribute.

Parameters
  • value (str) –

  • ns_map (Dict) –

Return type

str

classmethod bind_element(params, metadata, txt, tail, attrs, ns_map)[source]

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

Parameters
classmethod bind_element_attrs(params, metadata, attrs, ns_map)[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
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
Return type

Optional[XmlVar]