Find all occurences of inner text in an xml file with etree
<p>I am new to python and trees at all, and have encountered some problems.</p>

<p>I have the following dataset structured as:</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;graphml xmlns="http://graphml.graphdrawing.org/xmlns"&gt;
  &lt;node id="node1"&gt;
    &lt;data key="label"&gt;node1&lt;/data&gt;
    &lt;data key="degree"&gt;6&lt;/data&gt;
  &lt;/node&gt;
  &lt;node id="node2"&gt;
    &lt;data key="label"&gt;node2&lt;/data&gt;
    &lt;data key="degree"&gt;32&lt;/data&gt;
  &lt;/node&gt;
  &lt;node id="node3"&gt;
    &lt;data key="label"&gt;node3&lt;/data&gt;
    &lt;data key="degree"&gt;25&lt;/data&gt;
  &lt;/node&gt;
&lt;/graphml&gt;
</code></pre>

<p>I wish to be able to reach and print all the inner text of the &lt; data key="label"> elements using etree. In other words get the following result:</p>

<pre><code>"node1"
"node2"
"node3"
</code></pre>

<p>I have tried the itertext() with no luck (<a href="https://docs.python.org/2/library/xml.etree.elementtree.html#xml.etree.ElementTree.Element.itertext" rel="nofollow">https://docs.python.org/2/library/xml.etree.elementtree.html#xml.etree.ElementTree.Element.itertext</a>), as well as faulty xpath expressions.</p>

<p>I'm sure there is a simple solution to this, hope you guys can help!</p>

<p>This does the job on python 2.7 :</p>

<pre><code>import xml.etree.ElementTree as ET
root = ET.fromstring(data)

elts = root.findall('.//*[@key="label"]')
for e in elts:
    print(e.text)
</code></pre>

python xml xpath tree elementtree