SAX questions...

Discussion in 'Python' started by Timothy Grant, Jul 22, 2003.

  1. 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
     
    Timothy Grant, Jul 22, 2003
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ali Syed
    Replies:
    3
    Views:
    565
    Mark McIntyre
    Oct 13, 2004
  2. pkirk25
    Replies:
    50
    Views:
    1,132
    Bill Pursell
    Oct 4, 2006
  3. Replies:
    10
    Views:
    559
  4. Vijay
    Replies:
    2
    Views:
    601
    Öö Tiib
    May 7, 2010
  5. reema
    Replies:
    0
    Views:
    282
    reema
    Aug 26, 2008
Loading...

Share This Page