Newbie to XML in Python

Jeremy Jones zanesdad at bellsouth.net
Fri Aug 20 10:36:49 EDT 2004


Jens Thiede wrote:

> XML in Python doesn't seem easy or intuitive. All I need to do, is to 
> interpret a small piece of XML in which I store data for the contents 
> of an autorun menu. What is the quickest/most effective way to do this?
>
> What should I use for this; SAX or DOM - and which parser of ether 
> one, or niether (if there is a third option)?
>
> What are your views,
>
> Jens.

depends....  I've had a lot of success parsing smallish XML files with 
DOM.  The thing I like about DOM is that you are the one walking through 
the XML as you see fit by getting child nodes and attributes and blah 
blah blah.  With SAX (which I've not used much), you setup handlers, the 
methods of which get called when tags are hit, which pretty much forces 
you to setup a state machine to keep track of where you are in the 
document.  I looked into xpath, but wasn't able to quickly figure out 
how to update attributes, but looked great just for querying an XML 
file.  I don't know the format of the autorun file you mentioned, but if 
it's small and all you need to do is query it, you may want to expand 
your sights to include xpath.


Jeremy



More information about the Python-list mailing list