Relative Content

Tag Archive for pythonxml

Convert XML file into dictionary, with ElementTree

I have an XML configuration file used by legacy software, which I cannot change or format. The goal is to use Python 3.9 and transform the XML file into a dictionary, using only xml.etree.ElementTree library.

Force python to write namespace in root tag

I’m using python to generate an XML document for a third party. The third party has very precise ideas about how the final xml file shall look like. In my case it wants me to define a namespace in the root tag which is never used in the document. The
ET.ElementTree.write method is quite smart and defines only namespaces in the root tag which are used in the document. Is there a way to overcome its smartness and force it to write another additional namespace in the root tag?

Not able to get the correct xml output with Python script

All,
Trying to build a generic utility capable of converting dictionary data into xml.
It uses a config table to define the relationships between XML nodes.
The following script is almost giving me the output. The script is generating First Child Element for each data item, resulting in repetition of that element. Please find my script and actual output below and help me with getting the expected output:

Create dataframe from specific XML data in Python

I have an XML file (example shown below) that I want to have in a dataframe in Python. The issue is that the data in the XML has a specific structure and I’m having some trouble with getting the data I need.