xml_interface#

ioapps.xml_interface.read_xml(xml_path, remove_comments=False)[source]#

DESCRIPTION:

This function parses an XML-formatted file and returns the contents of the file formatted as a Python dictionary.

Parameters:
xml_path: str

A Python string specifying the path to the XML-formatted file to be read.

Keywords:
remove_comments: bool, optional

A Python boolean valued variable specifying whether to include XML-formatted comment strings when parsing the XML-formatted file.

Returns:
xml_dict: Dict

A Python dictionary containing the contents of the XML-formatted file path xml_path.

Raises:
XMLInterfaceError:
  • raised if the XML-formatted file path does not exist.

  • raised if an exception is encountered while reading the XML-formatted file path.

  • raised if an exception is encountered while replacing any defined special characters in the XML-formatted file path contents.

  • raised if an exception is encountered while parsing and defining the Python dictionary containing the contents of the XML-formatted file path specified upon entry (xml_path).

  • raised if an exception is encountered while creating a Python dictionary from the formatted contents of the XML-formatted file path specified upon entry (xml_path).

Return type:

Dict

ioapps.xml_interface.write_xml(xml_path, xml_dict, doc_name, dtd_path, indent=5)[source]#

DESCRIPTION:

This function writes a XML-formatted file xml_path containing the attributes within the Python dictionary xml_dict and the attributes defined by doc_name and dtd_path.

Parameters:
xml_path: str

A Python string specifying the path to the XML-formatted file to be written.

xml_dict: Dict

A Python dictionary containing the XML-attributes to be written to file path xml_path.

doc_name: str

A Python string defining the XML-formatted document name; see the example in the module documentation (above).

dtd_path: str

A Python string specifying the path to the document type definition (DTD) formatted file; this file contains the reference attributes to be resolved within the final XML-formatted file path; additional information regarding DTD-formatted files can be found here https://tinyurl.com/xml-dtd-example.

Keywords:
indent: int, optional

A Python integer specifying the total number of spaces for indenting when formatting the output XML-formatted file path xml_path.

Raises:
XMLInterfaceError:
  • raised if an exception is encountered while building the output XML-formatted file path xml_path.

Return type:

None