I am using a SAX parser (xml.sax) and it works how I want to. However, I am parsing quite a large file (hence why I use SAX) and I would like to stop parsing at some point (e.g., when I reached a certain limit, or when I found a certain piece of data).
class ProductHandler(xml.sax.ContentHandler):
def startElement(self, tag, attrs):
[.. process start ..]
def endElement(self, tag):
[.. process end ..]
def characters(self, content):
[.. process characters ..]
product_handler = ProductHandler()
parser = xml.sax.make_parser()
parser.setContentHandler(product_handler)
parser.parse(xmlfile)
How do I do that? Is there a certain return value I can return at one of the handler methods? I checked the documentation, but I couldn't find anything in this direction.