maci.xmldump

dumps element or elementtree data to a file as xml

dumping a file

Dumps Element or ElementTree object data to a file formatted as XML. Nothing is returned. Creates a new or overwrites an existing file by default (See append parameter to change mode).

Basic Example of dumping data to a file using default positional parameters

maci.xmldump('mydata.xml', data)

In this example, we simply dump data to a file using the xmldump function and pass a string of the filepath to the file as the first argument to the function, then pass the data as the second argument to the function.

To learn more about building out your xml ElementTree data in code, see xmlbuildmanual More information on using Element and ElementTree data: Youtube Video Search: https://www.youtube.com/results?search_query=python+xml+etree Documentation: https://docs.python.org/3/library/xml.etree.elementtree.html

partner functions

Functions that are related for ElementTree

maci.xmlload -> Loads xml data from a file as Element or ElementTree object maci.xmlloadstr -> Loads xml data from a string as Element object maci.xmldumpstr -> Dumps xml data to a string from xml etree Element object maci.xmlbuildmanual -> Returns empty xml ElementTree object to manually build xml data maci._defuse_xml_stdlib -> Monkey patch and defuse all stdlib packages [security use]

parameters & arguments

Describes all parameter functionality and accepted data types

filename: str | Path

First required positional argument. Accepts strings and Path objects

Use this parameter to point to your filepath

data: ElementTree | Element

Second required positional argument. Accepts ElementTree or Element objects

Use this parameter to pass in the data you want to dump to a file.

append: bool

Optional parameter. Accepts booleans. Default = False. File must already exist.

Use this parameter to enable appending mode to write by appending data to the file. Default is disabled which writes new or overwrites a file.

encoding: str | None

Optional parameter. Accepts strings or None. Default = None

Use this parameter to dump the data with the desired codec of the data if needed. The default uses the default of python, so you don't have to use this, but you can if the data needs to be written with a specific codec.

This function uses the native xml library etree shipped with the python standard library for its underlying functionality. For more information on the xml.etree api, visit: https://docs.python.org/3/library/xml.etree.elementtree.html

Security awareness: It is important to evaluate handling XML data carefully as there are known vulnerabilities in dealing with XML data. Please refer to the official python documentation above.

Additionally, see the provided tooling to potentially assist with vulnerabilities _defuse_xml_stdlib

Last updated