是否有任何 sax 库支持根据某些条件提前退出?

发布于 2024-12-22 14:35:37 字数 372 浏览 1 评论 0原文

我有一个如下所示的 xml 文件:

<root>
<application-key>ABC2349293493</application-key>
...
..
</root>

该 xml 文件相当大,我只需要获取应用程序密钥即可查看此请求是否应受到速率限制。

我的服务器受到攻击,因此我需要一种方法来限制请求速率,而无需读取整个 xml。

由于内存占用,DOM 是不可能的。

我对 SAX 很满意,但使用 xerces 你无法停止对 xml 的处理,因为它是推送模型。到目前为止我知道的唯一方法是抛出异常。

其他 sax 库是否支持优雅地提前退出?

I have an xml file that looks like:

<root>
<application-key>ABC2349293493</application-key>
...
..
</root>

The xml file is rather large, and I only need to get the application-key to see if this request should be rate limited.

My server is getting pounded, so I need a way to rate limit requests without having to read the entire xml.

DOM is out of the question because of the memory footprint.

I am happy with SAX, but with xerces you are not able to stop processing of the xml since it is a push model. The only way I know so far is the throw an exception.

Do any of the other sax libraries support exiting early gracefully?

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

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

发布评论

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

评论(2

岁吢 2024-12-29 14:35:37

StAX(XML 流式 API)拉解析器。 选择正确的实施也很重要:最佳 StAX 实施

PS 我仍然认为 SAX 的处理方式(抛出异常)更简单。

StAX (Streaming Api for XML) pull parser. Choosing the proper implementation is also important: Best StAX Implementation.

P.S. I still think SAX way of doing things (throwing an exception) is simpler.

尾戒 2024-12-29 14:35:37

异常确实是规范中可用于退出解析过程的唯一选项。如Java 所述。萨克斯解析器。如何手动中断解析?如何随时停止用SAX解析xml文档?

如果您真的不想使用异常,请切换到拉解析器,但我认为这并不重要。

An exception is indeed the only option in the spec that is available to exit the parsing process. As outlined Java. Sax parser. How to manually break parsing? or How to stop parsing xml document with SAX at any time?.

Switch to a pull parser if you REALLY don't want to use an exception, but I don't think it really matters.

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