I am trying to merge multiple XML files together using Python and no external libraries. The XML files have nested elements. Sample File 1: Sample File 2: What I Want: What I have tried: From this answer. What I Get: I hope you can see and understand my problem. I am looking for a proper solution, any guidance would be
Tag: elementtree
How to get all sub-elements of an element tree with Python ElementTree?
I want to find a way to get all the sub-elements of an element tree like the way ElementTree.getchildren() does, since getchildren() is deprecated since Python version 2.7. I don’t want to use it anymore, though I can still use it currently. Answer All sub-elements (descendants) of elem: A more complete example: To exclude the root itself:
Converting xml to dictionary using ElementTree
I’m looking for an XML to dictionary parser using ElementTree, I already found some but they are excluding the attributes, and in my case I have a lot of attributes. Answer Call as This works as long as you don’t actually have an attribute text; if you do, then change the third line in the function body to use a