SAX XML Parse Python error message

Waldemar Osuch waldemar.osuch at gmail.com
Sun Jul 13 23:30:41 CEST 2008


On Jul 13, 3:00 pm, goldtech <goldt... at worldpost.com> 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

Initialize self.coodinates in the __init__
or indent the "print  self.description, str(self.coordinates)"
one more level.
You have to remember that "endElement" is being called on the end
of every element.  In your case it is called by </description> but
the parser did not see <coordinates> yet.

In "def characters" you should be collecting the "ch" in a buffer.
It may be called multiple times for the same element.
Something like "self.description += ch" would do for starters.

Also you do not need to convert self.coordinates to string before
printing, it is already a string and even if it was not "print"
would convert it for you.

That's it for now :-) Others may spot more issues with
your code or my response.
On the positive side I really liked how you asked
the question.  There was a short runnable example and traceback.

Waldemar



More information about the Python-list mailing list