Your XML is incorrect. It must have exactly one top-level element. From Wikipedia :
Each XML document has exactly one single root element. It covers all other elements and, therefore, is the only parent element for all other elements. ROOT elements are also called PARENT elements.
Try to wrap it in an additional tag (e.g. Tables ) and parse it with ET:
xmlData = '''<Tables> <Table><Claimable>false</Claimable><MinorRev>80601</MinorRev><Operation>530600 ION MILL</Operation><HTNum>162</HTNum><WaferEC>80318</WaferEC><HolderType>HACARR</HolderType><Job>167187008</Job></Table> <Table><Claimable>false</Claimable><MinorRev>71115</MinorRev><Operation>530600 ION MILL</Operation><Experiment>6794</Experiment><HTNum>162</HTNum><WaferEC>71105</WaferEC><HolderType>HACARR</HolderType><Job>16799006</Job></Table> </Tables> ''' import xml.etree.ElementTree as ET xml = ET.fromstring(xmlData) for table in xml.getiterator('Table'): for child in table: print child.tag, child.text
Since Python 2.7 getiterator('Table') should be replaced with iter('Table') :
for table in xml.iter('Table'): for child in table: print child.tag, child.text
This gives:
Claimable false MinorRev 80601 Operation 530600 ION MILL HTNum 162 WaferEC 80318 HolderType HACARR Job 167187008 Claimable false MinorRev 71115 Operation 530600 ION MILL Experiment 6794 HTNum 162 WaferEC 71105 HolderType HACARR Job 16799006
source share