UserXmlParser#
- class xsdata.formats.dataclass.parsers.UserXmlParser(config=<factory>, context=<factory>, handler=<class 'xsdata.formats.dataclass.parsers.handlers.native.XmlEventHandler'>)[source]#
Xml parser for dataclasses with hooks to events.
The event hooks allow custom parsers to inject custom logic between the start/end element events.
- Parameters:
config (
ParserConfig
) – The parser config instancecontext (
XmlContext
) – The xml context instancehandler (
Type
[XmlHandler
]) – The xml handler class
- ns_map#
The parsed namespace prefix-URI map
- hooks_cache#
The hooks cache is used to avoid inspecting the class for custom methods on duplicate events.
- handler#
alias of
XmlEventHandler
- start(clazz, queue, objects, qname, attrs, ns_map)[source]#
Build and queue the XmlNode for the starting element.
Override to emit the start element event.
- Parameters:
clazz (
Optional
[Type
]) – The target class type, auto locate if omittedqueue (
List
[XmlNode
]) – The XmlNode queue listobjects (
List
[Tuple
[Optional
[str
],Any
]]) – The list of all intermediate parsed objectsqname (
str
) – The element qualified nameattrs (
Dict
) – The element attributesns_map (
Dict
) – The element namespace prefix-URI map
- end(queue, objects, qname, text, tail)[source]#
Parse the last xml node and bind any intermediate objects.
Override to emit the end element event if the binding process is successful.
- Parameters:
- Return type:
- Returns:
Whether the binding process was successful.
- 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)
- __eq__(other)#
Return self==value.
- __hash__ = None#
- from_bytes(source, clazz=None)#
Parse the input source bytes object into the target class type.
If no clazz is provided, the binding context will try to locate it from imported dataclasses.
- from_path(path, clazz=None)#
Parse the input file into the target class type.
If no clazz is provided, the binding context will try to locate it from imported dataclasses.
- from_string(source, clazz=None)#
Parse the input source string into the target class type.
If no clazz is provided, the binding context will try to locate it from imported dataclasses.
- parse(source, clazz=None)#
Parse the input file or stream into the target class type.
If no clazz is provided, the binding context will try to locate it from imported dataclasses.