mh_utils.xml

Functions and classes for handling XML files.

Classes:

XMLFileMixin()

ABC mixin to provide a function for instantiating the class from an XML file.

Functions:

get_validated_tree(xml_file[, schema_file])

Returns a validated lxml objectify from the given XML file, validated against the schema file.

class XMLFileMixin[source]

Bases: ABC

ABC mixin to provide a function for instantiating the class from an XML file.

Methods:

from_xml(element)

Construct an object from an XML element.

from_xml_file(filename)

Generate an instance of this class by parsing an from an XML file.

abstract classmethod from_xml(element)[source]

Construct an object from an XML element.

classmethod from_xml_file(filename)[source]

Generate an instance of this class by parsing an from an XML file.

Parameters

filename (Union[str, Path, PathLike]) – The filename of the XML file.

get_validated_tree(xml_file, schema_file=None)[source]

Returns a validated lxml objectify from the given XML file, validated against the schema file.

Parameters
Return type

_ElementTree

Returns

An lxml ElementTree object. When .getroot() us called on the tree the root will be an instance of lxml.objectify.ObjectifiedElement.