Over a million developers have joined DZone.

Using ElementTree

DZone's Guide to

Using ElementTree

Free Resource
ElementTree is a library that make XML processing in python
much, much easier. It will be included in Python 2.5 too.
Here's how to use it to read/extract XML

from elementtree.ElementTree import parse
tree = parse(filename)
doc = tree.getroot()

# Element type (name): 
print doc.tag
# Element text: 
print doc.text
# get the child of element type book
book = doc.find('book')

# element's attribute

# first matching element's text
booktext = doc.findtext('book')

Read more here and here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}