XML parsing with python

John Posner jjposner at optimum.net
Mon Aug 17 11:31:30 EDT 2009


> Use the iterparse() function of the xml.etree.ElementTree package.
>
> http://effbot.org/zone/element-iterparse.htm
> http://codespeak.net/lxml/parsing.html#iterparse-and-iterwalk
>
> Stefan
>   

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


-John




More information about the Python-list mailing list