views:

336

answers:

1

I am parsing an XML file with SAXReader and would like to stop after a certain amount of time (timeout) in case the file is too large. At a high level, I would like to throw a SAXException in the ContentHandler (in, say, startElement).

The idea is described here: http://www.ibm.com/developerworks/xml/library/x-tipsaxstop/

However, dom4j's SAXReader uses ElementHandler where the "onStart" and "onEnd" events don't allow throwing of exceptions. I'm a little stuck as to what to do here.

Any suggestions? Thanks.

+1  A: 

You could always throw a runtime exception when you get too many. Either make your own or use one of the existing ones that normally doesn't otherwise occur and use it as a means of getting out.

cletus