In [2]:
import xml.etree.ElementTree as ET
In [4]:
tree = ET.parse('country_data.xml')
In [5]:
root = tree.getroot()
In [7]:
root.tag
Out[7]:
In [8]:
root.attrib
Out[8]:
In [9]:
for child in root:
print child.tag, child.attrib
In [10]:
root[0][1].text
Out[10]:
In [11]:
for neighbor in root.iter('neighbor'):
print neighbor.attrib
In [12]:
for country in root.findall('country'):
rank = country.find('rank').text
name = country.get('name')
print name, rank
In [ ]: