See the docs
import xml.etree.ElementTree as ET
tree = ET.parse('country_data.xml')
root = tree.getroot()
root = ET.fromstring(country_data_as_string)
root.tag
root.attrib
for child in root:
print(child.tag, child.attrib)
root[0][1].text
See example xml below
for neighbor in root.iter('neighbor'): # iterate recursively finding neighbor elements
print(neighbor.attrib)
for country in root.findall('country'): # direct descendents only
rank = country.find('rank').text # first matching
name = country.get('name')
print(name, rank)
Example XML
<?xml version="1.0"?>
<data>
<country name="Liechtenstein">
<rank>1</rank>
<year>2008</year>
<gdppc>141100</gdppc>
<neighbor name="Austria" direction="E"/>
<neighbor name="Switzerland" direction="W"/>
</country>
<country name="Singapore">
<rank>4</rank>
<year>2011</year>
<gdppc>59900</gdppc>
<neighbor name="Malaysia" direction="N"/>
</country>
<country name="Panama">
<rank>68</rank>
<year>2011</year>
<gdppc>13600</gdppc>
<neighbor name="Costa Rica" direction="W"/>
<neighbor name="Colombia" direction="E"/>
</country>
</data>