John Posner wrote: >> Use the iterparse() function of the xml.etree.ElementTree package. > > iterparse() is too big a hammer for this purpose, IMO. How about this: > > from xml.etree.ElementTree import ElementTree > tree = ElementTree(None, "myfile.xml") > for elem in tree.findall('//book/title'): > print elem.text
Is that really so much better than an iterparse() version? from xml.etree.ElementTree import ElementTree for _, elem in ElementTree.iterparse("myfile.xml"): if elem.tag == 'book': print elem.findtext('title') elem.clear() Stefan -- http://mail.python.org/mailman/listinfo/python-list