SAX XML Parse Python error message

Fredrik Lundh fredrik at pythonware.com
Tue Jul 15 07:04:17 EDT 2008


goldtech wrote:

> I would be grateful for support with the code I cited. It's not long
> and fairly standard. I'm sure my error(s) would be glaring to more
> experienced coders. I appreciated the "heads-up" about other options
> but I would be grateful for help getting this code to run. Thanks

For comparison, here's how an experienced Python programmer might prefer 
to write your code:

     import xml.etree.cElementTree as ET

     description = None # most recently seen description

     for event, elem in ET.parse("somefile.xml"):
         if elem.tag == "description":
             description = elem.text
         elif elem.tag == "coordinates":
             print description.strip(), elem.text.strip()

You may want to ask yourself why you prefer to struggle with obsolete, 
error-prone, and slow technology when there are more efficient tools 
available in Python's standard library.

(the lxml library that Stefan linked to is a superset of xml.etree, in 
case you want more XML features).

</F>




More information about the Python-list mailing list