Guido van Rossum wrote:
> On 12/13/05, Walter Dörwald <[EMAIL PROTECTED]> wrote:
> > Having to define classes that conform to a certain API and registering
> > instances of those classes as callbacks with the parser doesn't look
> > that pythonic to me. An iterator API seems much more pythonic.
>
> Perhaps. Although the SAX API lets you leave a callback undefined if
> you don't have a need to handle those events; that's a bit trickier to
> do with an iterator.

Well, suppose you want to dump the text of a document.

    for e in iterparse(filename):
        if e.isText():
            out.write(e.data)

Not tricky.

> > Also the different callbacks have different signatures.

True.  With SAX I always have to look up the signatures.  The iterator
yields Node-like objects in document order.  I don't have to remember
signatures.

But the biggest advantage of an iterator-based API would be: when you
hit an element, you can easily pass control to a function that knows
how to parse that particular element.  parsePlay() can call
parseAct(), which can call parseScene().  To do anything like that
with SAX, you have to write a bunch of dispatch code.

-j
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to