title: Python: large XML parsing with multiple children of root tree
body: <p>Need to parse the large XML file with python (xml.etree.ElementTree) to process and generate a report as shown in expected section.</p>
  
  <p>I can't figure out how to get down until 4th level for certain details and from there into 5th level for it's respective/associated data. Where to loop and how to reference the children, is my problem. Please give any suggestions that you may have, thank you. </p>
  
  <pre><code>Input XML File: raw_data.xml
  
  &lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;
  &lt;FirstLevel Flevel="my1"&gt;
      &lt;SecondLevel Slevel="my2"&gt;
          &lt;ThirdLevel Tlevel="my3"&gt;
              &lt;FourthLevel test="1" mydata="Needed1"&gt;
                  &lt;FifthLevel associated="Required for Needed1"/&gt;
              &lt;/Fourthlevel&gt;  
              &lt;FourthLevel test="2" mydata="Needed2"&gt;
                  &lt;FifthLevel associated="Required for Needed2"/&gt;
              &lt;/Fourthlevel&gt;  
              &lt;FourthLevel test="3" mydata="Needed3"&gt;
                  &lt;FifthLevel associated="Required for Needed3-1"/&gt;
                  &lt;FifthLevel associated="Required for Needed3-2"/&gt;
              &lt;/Fourthlevel&gt;  
              &lt;FourthLevel test="4" mydata="Needed4"&gt;
                  &lt;FifthLevel associated="Required for Needed4-1"/&gt;
                  &lt;FifthLevel associated="Required for Needed4-2"/&gt;
              &lt;/Fourthlevel&gt;  
          &lt;/ThirdLevel&gt;
      &lt;/SecondLevel&gt;
  &lt;/FirstLevel&gt;
  -----------------------------------------------------------
  
  My Code:
  
      import xml.etree.ElementTree as ET
      tree = ET.parse('raw_data.xml')
      root=tree.getroot()
      mylevel=root.findall('.//FourthLevel')
      for i in mylevel:
          print ("mydata=",i.get('mydata'),"\t")
          assoc=root.findall('.//FifthLevel') ### assoc: Temporary variable for associated data
          for j in assoc:
               print ("associated=",j.get('associated'),"\n")
  
  
  
  
  Output: final_output.txt
  
  mydata=Needed1  associated=Required for Needed1
  mydata=Needed2  associated=Required for Needed2
  mydata=Needed3  associated=Required for Needed3-1
  mydata=Needed3  associated=Required for Needed3-1
  mydata=Needed4  associated=Required for Needed4-1
  mydata=Needed4  associated=Required for Needed4-1
  </code></pre>