dom4j SAXReader - 停止解析

发布于 2024-07-24 23:38:42 字数 423 浏览 2 评论 0原文

我正在使用 SAXReader 解析 XML 文件,并希望在一定时间(超时)后停止,以防文件太大。 在较高的层面上,我想在 ContentHandler 中(例如,在 startElement 中)抛出 SAXException。

这里描述了这个想法: http://www.ibm.com/developerworks /xml/library/x-tipsaxstop/

但是,dom4j 的 SAXReader 使用 ElementHandler,其中“onStart”和“onEnd”事件不允许抛出异常。 我有点不知道在这里做什么。

有什么建议么? 谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

画中仙 2024-07-31 23:38:42

当你得到太多时,你总是可以抛出运行时异常。 要么自己制作,要么使用通常不会发生的现有的一种,并将其用作逃脱的手段。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文