title: Python: 'NoneType' object has no attribute 'text', XML Parsing
body: <p>I am trying to take an XML file with Spirit, parse data, and output as a csv file. I feel like I am overlooking something easy. I am having an error:</p>
  <pre><code>Traceback (most recent call last):
    File &quot;xml2csv.py&quot;, line 12, in &lt;module&gt;
      name = i.find(&quot;spirit:name&quot;).text
  AttributeError: 'NoneType' object has no attribute 'text'
  </code></pre>
  <p>Sample XML File:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;spirit:component xmlns=&quot;http://www.spiritconsortium.org/XMLSchema/SPIRIT/1.5&quot;
    xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
    xmlns:spirit=&quot;http://www.spiritconsortium.org/XMLSchema/SPIRIT/1.5&quot;
    xsi:schemaLocation=&quot;http://www.spiritconsortium.org/XMLSchema/SPIRIT/1.5 http://www.spiritconsortium.org/XMLSchema/SPIRIT/1.5/memoryMap.xsd&quot;&gt;
  &gt;
  &lt;spirit:generic&gt;
  &lt;spirit:name&gt;GENERIC_NAME&lt;/spirit:name&gt;
  &lt;spirit:description&gt;GENERIC_DESCRIPTION&lt;/spirit:description&gt;
  &lt;/spirit:generic&gt;
  &lt;/spirit:component&gt;
  </code></pre>
  <p>My Python Code:</p>
  <pre><code># Importing the required libraries
  import xml.etree.ElementTree as Xet
  import pandas as pd
    
  cols = [&quot;name&quot;, &quot;description&quot;]
  rows = []
    
  # Parsing the XML file
  xmlparse = Xet.parse('xml_sample.xml')
  root = xmlparse.getroot()
  for i in root:
      name = i.find(&quot;spirit:name&quot;).text
      description = i.find(&quot;spirit:description&quot;).text
    
      rows.append({&quot;spirit:name&quot;: name,
                   &quot;spirit:description&quot;: description})
    
  df = pd.DataFrame(rows, columns=cols)
    
  # Writing dataframe to csv
  df.to_csv('output.csv')
  </code></pre>
  <p>I suspected my error was in my &quot;.text&quot; based on some other threads I was reading. However, removal of this leads to my .csv file not showing any data.</p>
  <p>CSV:</p>
  <pre><code>,name,description
  0,,
  </code></pre>
  <p>Any suggestions would be greatly appreciated. Kinda stuck on this.</p>