I have an xml file and I am trying to iterate through the tags to convert it to a pandas dataframe. My current process is to open the XML file with excel as an "XML table" but this takes forever. Trying to find a similar process in Python.
I am trying to follow along with the code presented on numerous other Stack Overflow questions and articles such as here here and here
I believe there are 2 problems I am facing:
Does having the namespace affect my xml?
I don't want to specify all of my tags as seen as a solution in 19.7.1.6. of the Element Tree documentation. I just want all of my tags to appear as a column for each "Security." If it doesn't have that tag it should be null. I also do not want to do a nasty if-else.
The problem is that when I run the code:
import xml.etree.ElementTree as et
etree = et.parse(xml_path)
test = etree.getroot()
and try and iterate as suggested in the above links, I am not able to easily access the child nodes.
Sample File:
<?xml version="1.0"?>
<SecurityInformation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://tempuri.org/SecurityInformation.xsd">
<Security>
<Country>United States</Country>
</Security>
</SecurityInformation>