xsdata.formats.dataclass.parsers.utils module

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

Bases: object

classmethod xsi_type(attrs, ns_map)[source]

Parse the xsi:type attribute if present.

Parameters
Return type

Optional[str]

classmethod data_type(attrs, ns_map)[source]

Convert the xsi:type attribute to a DataType, defaults to DataType.STRING.

Parameters
Return type

DataType

classmethod is_nillable(attrs)[source]

Return whether the element attrs has xsi:nil=”false”.

Parameters

attrs (Dict) –

Return type

bool

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_objects(params, meta, position, objects)[source]

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

Parameters
classmethod bind_mixed_objects(params, var, pos, objects)[source]

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

Parameters
classmethod bind_var(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_wild_var(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
Return type

bool

classmethod bind_wild_content(params, var, txt, tail, attrs, ns_map)[source]

Extract the text and tail content and bind it accordingly in the params dictionary. Return if any data was bound.

  • 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
Return type

bool

classmethod bind_content(params, metadata, txt, ns_map)[source]

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

Return if any data was bound.

Parameters
Return type

bool

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

Prepare parsed value before binding to a wildcard field.

Parameters
  • qname (str) –

  • value (Any) –

Return type

Any

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 fetch_any_children(position, objects)[source]

Fetch the children of a wildcard node.

Parameters
  • position (int) –

  • objects (List) –

Return type

List