SAX questions...

T

Timothy Grant

I've worked with DOM before, but never SAX, I have a script that seems to work
quite well, but every time I look at it I think it's amazingly unweildly and
that I must be doing something wrong.

def startElement(self, name, attr):
if name == "foo":
do_foo_stuff()
elif name == "bar":
do_bar_stuff()
elif name == "baz":
do_baz_stuff()

There's similar code in endElement() and characters() and of course, the more
tags that need processing the more unweildly each method becomes.

I could create a dictionary and dispatch to the correct method based on a
dictionary key. But it seems to me there must be a better way.

Is there?


--
Stand Fast,
tjg.

Timothy Grant
www.craigelachie.org
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top