How can I stop a SAX parser parsing an XML file?

Brian Ewins

This problem arises because org.xml.sax.XMLReader.parse() blocks until parsing is complete. It could be a problem on huge documents. Run the parser in another thread. Then kill the thread.

Slightly cleaner is to implement your own ContentHandler, (eg extending XMLFilterImpl) so that as soon as you tell it to stop listening, all events are ignored and the parser thread is killed - this prevents stray events making it through.