Over a million developers have joined DZone.

Using ElementTree

·
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
book.keys()
book.items()
book.get('COLOR')

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

Read more here and here.
Topics:

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

{{ parent.tldr }}

{{ parent.urlSource.name }}