REALLY simple xml reader

Diez B. Roggisch deets at
Sun Jan 27 18:50:06 CET 2008

Simon Pickles schrieb:
> Hi
> Can anyone suggest a really simple XML reader for python? I just want to 
> be able to do something like this:
> xmlDoc ="file.xml")
> element = xmlDoc.GetElement("foo/bar")
> ... to read the value of:
> <foo>
>   <bar>42</bar>
> </foo>

Since python2.5, the ElementTree module is available in the standard 
lib. Before 2.5, you can of course install it.

Your code then would look like this:

import xml.etree.ElementTree  as et

doc = """

root = et.fromstring(doc)

for bar in root.findall("bar"):
     print bar.text


More information about the Python-list mailing list