Simple XML-to-Python conversion

Thomas Guettler guettli at thomas-guettler.de
Thu Mar 17 08:15:59 EST 2005


Am Wed, 16 Mar 2005 14:19:49 -0800 schrieb gaudetteje at gmail.com:

> I've been searching high and low for a way to simply convert a small
> XML configuration file to Python data structures.  I came across gnosis
> XML tools, but need a built-in option for doing something similar.
> 
> My knowledge of DOM and anything beyond simple XML structures is
> rudimentary at best.  Is there a simple way to use SAX handlers to pull
> attributes and elements into Python lists/dictionaries?

Hi,

Just write a script which uses xml.sax. It is not difficult.
You get an event for every start-tag and for every end-tag.
The class which handles the events can build the structure
if your XML file.

The online version of the python cookbook has some
python and SAX examples,

 Thomas



-- 
Thomas Güttler, http://www.thomas-guettler.de/





More information about the Python-list mailing list