Class XML

class ooodev.io.xml.XML[source]
classmethod get_all_node_values(row_nodes, col_ids)[source]

Gets all node values.

The data from a sequence of <col> becomes one row in the generated 2D array.

The first row of the 2D array contains the col ID strings.

Parameters:
  • row_nodes (NodeList) – rows

  • col_ids (Sequence[str]) – Column ids

Returns:

2D-list of values on success; Otherwise, None

Return type:

List[list] | None

Note

col_ids must match the column names:

col_ids = ("purpose", "amount", "tax", "maturity")

static get_node(tag_name, nodes)[source]

Gets the fist tag_name found in nodes.

Parameters:
  • tag_name (str) – tag name to find in nodes.

  • nodes (XNodeList) – Nodes to search

Returns:

First found node; Otherwise, None

Return type:

XNode | None

static get_node_attr(attr_name, node)[source]

Get the named attribute value from node

Parameters:
  • attr_name (str) – Attribute Name

  • node (XNode) – Node to get attribute of.

Returns:

Attribute value if found; Otherwise empty str.

Return type:

str

classmethod get_node_value(node: com.sun.star.xml.dom.XNode)[source]
classmethod get_node_value(tag_name: str, nodes: com.sun.star.xml.dom.XNodeList)
classmethod get_node_value(*args, **kwargs)

Gets first tag_name node in the list and returns it text.

Parameters:
  • node (XNode) – Node to get value of.

  • tag_name (str) – tag_name to search for.

  • nodes (XNodeList) – List of nodes to search.

Returns:

Node value if found; Otherwise empty str.

Return type:

str

classmethod get_node_values(nodes)[source]

Gets all the node values

Parameters:

nodes (XNodeList) – Nodes to get values of.

Returns:

Node Values

Return type:

Tuple[str, …]

static get_xml_string(xml_element)[source]
Return type:

str

Parameters:

xml_element (Any) –

classmethod load_doc(fnm)[source]

Gets a document from a file

Parameters:

fnm (PathOrStr) – XML file to load.

Raises:

Exception – if unable to open document.

Returns:

XML Document.

Return type:

XDocument

static save_doc(doc, xml_fnm)[source]

Save doc to xml file.

Parameters:
  • doc (Document) – doc to save.

  • xml_fnm (PathOrStr) – Output file path.

Raises:

Exception – If unable to save document

Return type:

None

classmethod str_to_doc(xml_str)[source]

Gets a XML document from xml string.

Parameters:

xml_str (str) – XML string.

Raises:

Exception – if unable to create document from xml.

Returns:

XML Document on successful load; Otherwise, None.

Return type:

XDocument

classmethod url_2_doc(url)[source]

Gets a XML Document from remote source.

Parameters:

url (str) – URL for a remote XML Document

Raises:

Exception – if unable to open document.

Returns:

XML Document

Return type:

XDocument