I have a complex xml I'm trying to extract data from.
<?xml version="1.0" ?>
<root xmlns="something.something.com">
<Save>
<AdditionalInfo>
<Name></Name>
<Time></Time>
<UtilityVersion></UtilityVersion>
<XMLVersion></XMLVersion>
<PluginName></PluginName>
<ClassName></ClassName>
</AdditionalInfo>
<Data>
<session>
<xyDataObjects>
<xyData Key="'info'" ObjectType="moreinfo" Type="evenmoreinfo">
<axis1QuantityType ObjectType="guesswhat" Type="info!">
<label></label>
<type></type>
</axis1QuantityType>
... and so on and so on
The file has multiple blocks starting and ending with the Save and /Save blocks and the info I'm looking for can be as far as the label, or even farther.
ElementTree.Iter seemed to be my solution as it would iterate through every Save block and find the <label> info I am looking for, but unfortunately, it doesn't accept a namespace argument.
What are my other options? I'm trying to keep my code flexible, as I foresee that the structure of the xml file could change in the future, and simple so I would rather not implement something like:
tree= ET.parse('dblank.xml')
root = tree.getroot()
for i in range(len(root)):
Array[i]=root[i][1][0][0][0][0][0].text
xpathqueries to find the information you want. What have you tried so far?iter(); you just have to take the namespace of an element into account when checking a condition. Or you can usefindall()with a wildcard. See stackoverflow.com/a/61154644/407651