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.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.