ODXML
Contents
- class ooodev_xml.odxml.XML[source]
XML method used for with LibreOffice Documents
- static apply_xslt(xml_fnm, xls_fnm)[source]
Transforms xml file using XLST.
Not available in macros at this time.
- Parameters:
xml_fnm (PathOrStr) – XML source file path.
xls_fnm (PathOrStr) – XSL source file path.
- Raises:
Exception – If unable to apply xls
- Returns:
String of XML that has been transformed.
- Return type:
str
- static apply_xslt_to_str(xml_str, xls_fnm)[source]
Transforms xml using XLST.
Not available in macros at this time.
- Parameters:
xml_str (str) – Raw XML data.
xls_fnm (PathOrStr) – XSL source file path.
- Raises:
Exception – If unable to apply xls
- Returns:
String of XML that has been transformed.
- Return type:
str
- classmethod get_all_node_values(row_nodes, col_ids)[source]
Gets all node values.
Example XML
XML is assumed to have structure that is similar
<?xml version="1.0"?> <payments> <payment> <purpose>CD</purpose> <amount>12.95</amount> <tax>19.1234</tax> <maturity>2008-03-01</maturity> </payment> <payment> <purpose>DVD</purpose> <amount>19.95</amount> <tax>19.4321</tax> <maturity>2008-03-02</maturity> </payment> <payment> <purpose>Clothes</purpose> <amount>99.95</amount> <tax>18.5678</tax> <maturity>2008-03-03</maturity> </payment> <payment> <purpose>Book</purpose> <amount>9.49</amount> <tax>18.9876</tax> <maturity>2008-03-04</maturity> </payment> </payments>
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")Results for example xml:
[ ['CD', '12.95', '19.1234', '2008-03-01'], ['DVD', '19.95', '19.4321', '2008-03-02'], ['Clothes', '99.95', '18.5678', '2008-03-03'], ['Book', '9.49', '18.9876', '2008-03-04'] ]
- classmethod get_flat_filter_name(doc_type)[source]
Gets the Flat XML filter name for the doc type.
- Parameters:
doc_type (Lo.DocTypeStr) – Document type.
- Returns:
Flat XML filter name.
- Return type:
str
- 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 (NodeList) – Nodes to search
- Returns:
First found node; Otherwise, None
- Return type:
Node | None
- static get_node_attr(attr_name, node)[source]
Get the named attribute value from node
- Parameters:
attr_name (str) – Attribute Name
node (Node) – Node to get attribute of.
- Returns:
Attribute value if found; Otherwise empty str.
- Return type:
str
- classmethod get_node_value(node: xml.dom.minidom.Node)[source]
- classmethod get_node_value(tag_name: str, nodes: xml.dom.minicompat.NodeList)
- classmethod get_node_value(*args, **kwargs)
Gets first
tag_namenode in the list and returns it text.- Parameters:
node (Node) – Node to get value of.
tag_name (str) –
tag_nameto search for.nodes (NodeList) – 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 (NodeList) – Nodes to get values of.
- Returns:
Node Values
- Return type:
Tuple[str, …]
- classmethod indent(src: str) str[source]
- classmethod indent(src: os.PathLike) str
- classmethod indent(src: xml.dom.minidom.Document) str
- classmethod indent(src)
Indents xml
- Parameters:
src (str | PathLike | Document) – raw xml data or xml file path or xml document.
- Raises:
TypeError is src is not expected type –
Exception – If unable to indent
- Returns:
Indented xml as string.
- Return type:
str
- 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:
Document
- 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