From the sample xml below
<?xml version="1.0"?>
<data>
<country>
<name>Liechtenstein</name>
<rank>1</rank>
<year>2008</year>
<gdppc>141100</gdppc>
<neighbor name="Austria" direction="E"/>
<neighbor name="Switzerland" direction="W"/>
</country>
<country>
<name>Singapore</name>
<rank>4</rank>
<year>2011</year>
<gdppc>59900</gdppc>
<neighbor name="Malaysia" direction="N"/>
</country>
<country>
<name>Panama</name>
<rank>68</rank>
<year>2011</year>
<gdppc>13600</gdppc>
<neighbor name="Costa Rica" direction="W"/>
<neighbor name="Colombia" direction="E"/>
</country>
</data>
Using Python ElementTree
import xml.etree.ElementTree as ET
tree = ET.parse('test.xml')
for elem in tree.iter(tag='name'):
print (elem.tag)
displays three name elements. How can I retrive just one name element <name>Panama</name> with a specfic text.
for elem in tree.iter(tag="name='panama'"): not working