tags:

views:

93

answers:

1

Is there a way to halt the parsing from inside a content handler? Or is throwing an exception the only way?

Note that I am using xml.sax.parseString.

A: 

The complete API for Python's SAX content handlers is documented here: as you can see, the information flow is entirely one-way, parser to handler -- no way for the handler to supply info back to the parser (such as whether the parse should be terminated).

Therefore, as you had surmised and the commenters confirmed, "control-flow exceptions" are indeed the only way to achieve such a "premature termination". As the commenters mention, it's not too bad, after all.

Alex Martelli