UserXmlParser#

class xsdata.formats.dataclass.parsers.UserXmlParser(config=<factory>, context=<factory>, handler=<class 'xsdata.formats.dataclass.parsers.handlers.native.XmlEventHandler'>)[source]#

User Xml parser for dataclasses with hooks for emitting events to alter the behavior when an elements starts or ends.

Parameters:
Variables:
  • ms_map – The prefix-URI map generated during parsing

  • emit_cache – Qname to event name cache

handler#

alias of XmlEventHandler

start(clazz, queue, objects, qname, attrs, ns_map)[source]#

Start element notification receiver.

Build and queue the XmlNode for the starting element.

Parameters:
  • clazz (Optional[Type]) – Root class type, if it’s missing look for any suitable models from the current context.

  • queue (List[XmlNode]) – The active XmlNode queue

  • objects (List[Tuple[Optional[str], Any]]) – The list of all intermediate parsed objects

  • qname (str) – Qualified name

  • attrs (Dict) – Attribute key-value map

  • ns_map (Dict) – Namespace prefix-URI map

end(queue, objects, qname, text, tail)[source]#

End element notification receiver.

Pop the last XmlNode from the queue and use it to build and return the resulting object tree with its text and tail content.

Parameters:
Return type:

bool

emit_event(event, name, **kwargs)[source]#

Propagate event to subclasses.

Match event and name to a subclass method and trigger it with any input keyword arguments.

Example:

event=start, name={urn}bookTitle -> start_booking_title(**kwargs)
Parameters:
  • event (str) – Event type start|end

  • name (str) – Element qualified name

  • kwargs (Any) – Event keyword arguments

__eq__(other)#

Return self==value.

__hash__ = None#
from_bytes(source, clazz=None)#

Parse the input bytes array return the resulting object tree.

Return type:

TypeVar(T)

from_path(path, clazz=None)#

Parse the input file path and return the resulting object tree.

Return type:

TypeVar(T)

from_string(source, clazz=None)#

Parse the input string and return the resulting object tree.

Return type:

TypeVar(T)

parse(source, clazz=None)#

Parse the input stream or filename and return the resulting object tree.

Return type:

TypeVar(T)

register_namespace(prefix, uri)#

Add the given prefix-URI namespaces mapping if the prefix is new.

Parameters:
  • prefix (Optional[str]) – Namespace prefix

  • uri (str) – Namespace uri