XmlParser#

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

Default Xml parser for data classes.

Parameters:
ns_map#

The parsed namespace prefix-URI map

handler#

alias of XmlEventHandler

__eq__(other)#

Return self==value.

__hash__ = None#
end(queue, objects, qname, text, tail)#

Parse the last xml node and bind any intermediate objects.

Parameters:
  • queue (List[XmlNode]) – The XmlNode queue list

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

  • qname (str) – The element qualified name

  • text (Optional[str]) – The element text content

  • tail (Optional[str]) – The element tail content

Return type:

bool

Returns:

Whether the binding process was successful.

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.

Parameters:
  • source (bytes) – The source bytes object to parse

  • clazz (Optional[Type[TypeVar(T)]]) – The target class type to parse the source bytes object

Return type:

TypeVar(T)

Returns:

An instance of the specified class representing the parsed content.

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.

Parameters:
  • path (Path) – The path to the input file

  • clazz (Optional[Type[TypeVar(T)]]) – The target class type to parse the file into

Return type:

TypeVar(T)

Returns:

An instance of the specified class representing the parsed content.

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.

Parameters:
  • source (str) – The source string to parse

  • clazz (Optional[Type[TypeVar(T)]]) – The target class type to parse the source string into

Return type:

TypeVar(T)

Returns:

An instance of the specified class representing the parsed content.

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.

Parameters:
  • source (Any) – The source file or stream object to parse

  • clazz (Optional[Type[TypeVar(T)]]) – The target class type to parse the source bytes object

Return type:

TypeVar(T)

Returns:

An instance of the specified class representing the parsed content.

register_namespace(prefix, uri)#

Register the uri prefix in the namespace registry.

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

  • uri (str) – Namespace uri

start(clazz, queue, objects, qname, attrs, ns_map)#

Build and queue the XmlNode for the starting element.

Parameters:
  • clazz (Optional[Type]) – The target class type, auto locate if omitted

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

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

  • qname (str) – The element qualified name

  • attrs (Dict) – The element attributes

  • ns_map (Dict) – The element namespace prefix-URI map