title: Parsing XML data with python - how to capture everything in a more pythonic way?
body: <p>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.</p>
  <p>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.</p>
  <p>Currently, iterating like I have below uses too may layers of iteration with try/except that is very ugly!</p>
  <pre><code>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)
  </code></pre>
  <p>Any help would be greatly appreciated.</p>