Parsing XML in python for numbers
<p>I am new to python as well as XMl. I am trying to parse an XML file, find the  values and the sum of those values. I have included the code as well as the data below.</p>

<pre><code>import xml.etree.ElementTree as ET
data='''
&lt;place&gt;
  &lt;note&gt;Test data&lt;/note&gt;
  &lt;hospitals&gt;
    &lt;doctor&gt;
      &lt;name&gt;John&lt;/name&gt;
      &lt;count&gt;97&lt;/count&gt;
    &lt;/doctor&gt;
    &lt;doctor&gt;
      &lt;name&gt;Sam&lt;/name&gt;
      &lt;count&gt;97&lt;/count&gt;
    &lt;/doctor&gt;
    &lt;doctor&gt;
      &lt;name&gt;Luke&lt;/name&gt;
      &lt;count&gt;90&lt;/count&gt;
    &lt;/doctor&gt;
    &lt;doctor&gt;
      &lt;name&gt;Mark&lt;/name&gt;
      &lt;count&gt;90&lt;/count&gt;
    &lt;/doctor&gt;
  &lt;/hospitals&gt;
&lt;/place&gt; '''

tree=ET.fromstring (data)
for lines in tree.findall('place/hospitals/doctor'):
    print lines.get('count'), lines.text
</code></pre>

<p>When I execute the above code, I am not getting any output.
Then I changed the code to :</p>

<pre><code>tree=ET.fromstring (data)
print 'count:',tree.find('count').text
</code></pre>

<p>and the output is:</p>

<pre><code>Traceback (most recent call last):
  File "test2.py", line 26, in &lt;module&gt;
    print 'count:',tree.find('count').text
AttributeError: 'NoneType' object has no attribute 'text'
</code></pre>

<p>Any help is appreciated guys.
Thank you</p>