The aim is to capture all data in an xml file. Once captured, im comparing it to a reference xml file to ensure nothing has changed and to then tell you what the differences are.
What i wrote works for what I need, but is very cumbersome and a bit messy! Is there a better way to iterate through all items at all depths of an xml file? The solution just has to be robust to capture everything.
Currently, iterating like I have below uses too may layers of iteration with try/except that is very ugly!
import xml.etree.ElementTree as ET
def xml_iter(file):
tree = ET.parse(file)
root = tree.getroot()
namespaces = {}
List = []
Parent = []
for elem in root:
for i in elem:
try:
i = i.text.strip()
List.append(i)
except:
pass
for j in i:
try:
j = j.text.strip()
List.append(j)
except:
pass
for k in j:
try:
k = k.text.strip()
List.append(k)
except:
pass
return (List)
Any help would be greatly appreciated.