dom4j SAXReader-停止解析 [英] dom4j SAXReader - stop parsing
问题描述
我正在用SAXReader解析XML文件,并希望在一定时间(超时)后停止,以防文件太大.在较高的层次上,我想在ContentHandler中(例如,在startElement中)抛出SAXException.
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).
此处描述了该想法: http://www.ibm. com/developerworks/xml/library/x-tipsaxstop/
但是,dom4j的SAXReader使用ElementHandler,其中的"onStart"和"onEnd"事件不允许抛出异常.我对在这里做什么感到有些困惑.
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.
有什么建议吗?谢谢.
推荐答案
当收到太多异常时,您总是可以抛出运行时异常.要么自己制造,要么使用通常不会发生的现有装备中的一种,然后将其用作逃脱的手段.
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.
这篇关于dom4j SAXReader-停止解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!