Python Saxophone : Is there a way to halt the parsing from inside a content handler?

Python Saxophone : Is there a way to halt the parsing from inside a content handler? … here is a solution to the problem.

Python Saxophone : Is there a way to halt the parsing from inside a content handler?

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

Notice that I’m using xml.sax.parseString.

Solution

The full API that documents Python’s SAX content handler here : As you can see, the flow of information is completely one-way, from the parser to the handler – the handler cannot provide information back to the parser (e.g. whether the resolution should be terminated).

So, as your guess and commenters confirm, “control flow exceptions” are really the only way to achieve such “premature termination”. As commenters say, it’s not bad after all.

Related Problems and Solutions