dom4j SAXReader - stop parsing

心不动则不痛 提交于 2019-12-08 09:25:35

问题


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:


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.



来源:https://stackoverflow.com/questions/1020409/dom4j-saxreader-stop-parsing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!