ssapy_toolkit.IO.xml_utils

Functions

load_xml(filename[, keep_root, decode_special])

Alias of read_xml(), provided with the requested name.

read_xml(filename[, keep_root, decode_special])

Parse an XML file into Python data.

save_xml(filename, data[, root_tag, pretty, ...])

Serialize Python data to XML and write to 'filename'.

ssapy_toolkit.IO.xml_utils.load_xml(filename, keep_root=False, decode_special=True)[source]

Alias of read_xml(), provided with the requested name.

ssapy_toolkit.IO.xml_utils.read_xml(filename, keep_root=False, decode_special=True)[source]

Parse an XML file into Python data.

Args:

filename: Path-like or string to an XML file. keep_root (bool): If False (default), return the content of the root element.

If True, return {root_tag: content}.

decode_special (bool): If True (default), restore marked ndarray/datetime/Time/set/tuple.

Returns:

dict | list | str | int | float | bool | numpy.ndarray | datetime | astropy.time.Time

ssapy_toolkit.IO.xml_utils.save_xml(filename, data, root_tag='root', pretty=True, xml_declaration=True, encoding='utf-8')[source]

Serialize Python data to XML and write to ‘filename’.

  • Dict/List/Scalar supported.

  • Special encodings:
    • numpy.ndarray -> @attrs: type=”ndarray”, dtype, shape + <item> values

    • numpy scalars -> converted to native Python numbers

    • datetime -> @attrs: type=”datetime”, #text=ISO8601

    • astropy Time -> @attrs: type=”astropy_time”, scale + #text=ISOT

    • set/tuple -> @attrs: type=”set”/”tuple” + <item> children