DEV Community

Discussion on: XML with Python

Collapse
akshay090 profile image
Akshay090

Have you tried lxml its similar to element tree?

Collapse
minchulkim87 profile image
Min Author

Short answer is no.

I think when it came up in my initial searches, I wasn't able to use it (I work in a government where installing things that do not require Linux or compiling is okay but not so much the compile stuff, or use Linux which the lxml seems to be both).

But more to the point, they don't "do" anything besides just "read" the data. The thing that lxml offers over the regular xml package seems to be speed. On the otherhand, xmltodict offered an automated way for me to get to a point of simply converting to a pandas dataframe unlike xml or lxml. Both xml and lxml are "lower level" than pandas. If one needs to navigate through the xml trees, then xml and lxml seem like the way to go. But as with pretty much every other file type one typically use with pandas, I wanted a pd.read_file() type solution. Eventually, I need a table structure, not a tree structure. Getting from XML to normalised and separated dataframes was my goal, and the xml and lxml solutions don't get there on their own. I guess I could have used xml as the reading part rather than xmltodict, but xmltodict was nicer in that it was automated.