Parsing XML with Python
Using the ElementTree library in Module xml Example 1: Selecting elements with findall import xml.etree.ElementTree as ET input = '''<stuff> <users> <user x="x1"> <id>001</id> <name>John</name> </user> <user x="x2"> <id>002</id> <name>Sam</name> </user> </users> </stuff>''' stuff = ET.fromstring(input) lst = stuff.findall('users/user') print('User count:', len(lst)) for item in lst: print('Name:', item.find('name').text) print('ID:', item.find('id').text) print('Attribute:', item.get('x')) Example 2: