title: Python extract data from xml and save it to excel
body: <p>I would like to extract some data from an XML file and save it in a table format, such as XLS or DBF.</p>
  
  <p>Here is XML file i have:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"&gt;
    &lt;SOAP-ENV:Header /&gt;
    &lt;SOAP-ENV:Body&gt;
      &lt;ADD_LandIndex_001&gt;
        &lt;CNTROLAREA&gt;
          &lt;BSR&gt;
            &lt;VERB&gt;ADD&lt;/VERB&gt;
            &lt;NOUN&gt;LandIndex&lt;/NOUN&gt;
            &lt;REVISION&gt;001&lt;/REVISION&gt;
          &lt;/BSR&gt;
        &lt;/CNTROLAREA&gt;
        &lt;DATAAREA&gt;
          &lt;LandIndex&gt;
            &lt;reportId&gt;AMI100031&lt;/reportId&gt;
            &lt;requestKey&gt;R3278458&lt;/requestKey&gt;
            &lt;SubmittedBy&gt;EN4871&lt;/SubmittedBy&gt;
            &lt;submittedOn&gt;2015/01/06 4:20:11 PM&lt;/submittedOn&gt;
            &lt;LandIndex&gt;
              &lt;agreementdetail&gt;
                &lt;agreementid&gt;001       4860&lt;/agreementid&gt;
                &lt;agreementtype&gt;NATURAL GAS&lt;/agreementtype&gt;
                &lt;currentstatus&gt;
                  &lt;status&gt;ACTIVE&lt;/status&gt;
                  &lt;statuseffectivedate&gt;1965/02/18&lt;/statuseffectivedate&gt;
                  &lt;termdate&gt;1965/02/18&lt;/termdate&gt;
                &lt;/currentstatus&gt;
                &lt;designatedrepresentative&gt;
                &lt;/designatedrepresentative&gt;
              &lt;/agreementdetail&gt;
            &lt;/LandIndex&gt;
          &lt;/LandIndex&gt;
        &lt;/DATAAREA&gt;
      &lt;/ADD_LandIndex_001&gt;
    &lt;/SOAP-ENV:Body&gt;
  &lt;/SOAP-ENV:Envelope&gt;
  </code></pre>
  
  <p>I am interested in information inside the <em>agreementdetail</em> tag which is under DATAAREA/LandIndex/LandIndex/</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Thanks to <strong>MattDMo</strong> this task has moved a bit from its dead point. So I made this script below. It iterates the file and gets all instances of the <em>agreementdetail</em> and outputs <em>agreementid</em> and <em>agreementtype</em> for each.</p>
  
  <pre><code>import xml.etree.ElementTree as ET
  import arcpy
  
  xmlfile = 'D:/Working/Test/Test.xml'
  element_tree = ET.parse(xmlfile)
  root = element_tree.getroot()
  agreement = root.findall(".//agreementdetail")
  result = []
  elements = ('agreementid', 'agreementtype')
  
  for a in agreement:
      obj = {}
      for e in elements:
          obj[e] = a.find(e).text
      result.append(obj)
  
  arcpy.AddMessage(result)
  </code></pre>
  
  <p>The output I am receiving consists of a bunch of this strings: {'agreementid': '001       4860', 'agreementtype': 'NATURAL GAS'}</p>
  
  <p>Now I need to convert this output into a table format (.csv, .dbf, .xls etc.) so that agreementid and agreementtype are columns:</p>
  
  <pre><code>agreementid    | agreementtype 
  001       4860 | NATURAL GAS
  </code></pre>
  
  <p>I will be very grateful if you could guide me on how to accomplish it. Or maybe any example? </p>
  
  <p>P.S. Python version is 2.7</p>