I'm trying to find out how to retrieve XML attribute values using the cElementTree iterparse in Python (2.7). My XML is something like this:
<root>
<record attr1="a" attr2="b" attr3="c" ... />
<record attr1="x" attr2="y" attr3="z" ... />
...
</root>
My code is something like this:
context = ET.iterparse(sys.stdin, events=('start','end'))
context = iter(context)
event, root = context.next()
for event, elem in context:
if event == 'end' and elem.tag == 'record':
# get the attributes!!
elem.clear()
root.clear()
I'm dealing with big data from stdin. I'm not having any luck figuring this out. Could someone please tell how (optimal?) to do this?