I suggest ElementTree
. There are other compatible implementations of the same API, such as lxml
, and cElementTree
in the Python standard library itself; but, in this context, what they chiefly add is even more speed -- the ease of programming part depends on the API, which ElementTree
defines.
After building an Element instance e
from the XML, e.g. with the XML function, or by parsing a file with something like
e = xml.etree.ElementTree.parse('thefile.xml').getroot()
or any of the many other ways shown at ElementTree
, you just do something like:
for atype in e.findall('type'):print(atype.get('foobar'))
and similar, usually pretty simple, code patterns.