#XML Review Example #this code reads in a data file written by the # example_xml_writer.py code. # Copyright Jay Summet 2010 import xml.etree.ElementTree as etree filename = "exampleOUT.xml" #This line will read in the file and create the entire #tree of elements. tree = etree.parse(filename) #You can either follow the links to iterate #through each subelement: print("Example 1:") root = tree.getroot() for person in root: print( person.attrib['name']) for thing in person: print(" " , thing.tag, thing.text) print("Example 2:") #Or, you can search for all nodes that match a particular pattern #in the tree... aList = tree.findall("//Age") print(aList) for item in aList: print( item.text)