Using ElementTree
much, much easier. It will be included in Python 2.5 too.
Here's how to use it to read/extract XML
1 2 from elementtree.ElementTree import parse 3 tree = parse(filename) 4 doc = tree.getroot() 5 6 # Element type (name): 7 print doc.tag 8 # Element text: 9 print doc.text 10 # get the child of element type book 11 book = doc.find('book') 12 13 # element's attribute 14 book.keys() 15 book.items() 16 book.get('COLOR') 17 18 # first matching element's text 19 booktext = doc.findtext('book')
Read more here and here.