[XML-SIG] Re: Limit XML Parsing with SAX

Fredrik Lundh fredrik at pythonware.com
Tue Oct 12 10:43:15 CEST 2004

Henry Chan wrote:

> I'm a complete newbie to the world of XML and really python in general. I think I only clocked 
> about a month in python. Anyway, I was writing this script to parse the releases off of this anime 
> webpage. I want it to list the 5 most recent release elements. I've written something up using SAX 
> as I was reading the Python/XML How-to. It works but it's super slow. The way in which I have 
> limited the amount of release elements is by having a variable that increments each time a release 
> element is encountered. Then, it checks against the limit. If it's >= the limit, it returns. I 
> have that at the beginning of startElement(). It's pretty sloppy. I was hoping there would be a 
> way to stop parsing once this limit is hit instead of continue parsing while ignoring the results.

raise an exception inside the method, and catch it outside the parser
call.  here's an example:



More information about the XML-SIG mailing list