JAXP XSLT document() 函数问题

发布于 2024-11-15 16:10:46 字数 380 浏览 0 评论 0原文

我正在使用 XSLT 转换的 java 应用程序下工作。我其中有很多 document() 调用,因此可能会出现 java.lang.OutOfMemory 异常(我实际上有),因为每次调用 document() 函数后,文档都会被缓存。

http://xml.apache.org/xalan-j/faq。 html#faq-N102F9 我读到可以 增加堆内存大小,这不是我的情况的解决方案。我还尝试使用似乎不支持的增量变换。

那么,在使用 document() 函数时是否有可能关闭 jaxp 中的文档缓存?

I am working under java application which uses XSLT transformation. I have a lot of document() calls in it, so it is possible to have java.lang.OutOfMemory exception (which I actually have), because after each call of document() function the document is cached.

At http://xml.apache.org/xalan-j/faq.html#faq-N102F9 I read that it is possible to
increase heap memory size which is not the solution in my case. I also tried to use incremental transform which seems to be not supported.

So, is there any possibility to turn off document caching in jaxp while working with document() function?

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

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

发布评论

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

评论(3

没有心的人 2024-11-22 16:10:46

就像user1066037的回答一样,希望你可以切换到Saxon。 Saxon 有一个名为 saxon:discard-document 的扩展。它有 PE 版、EE 版或 Saxon-B 版本。在此处搜索“Saxon-B”: http://saxon.sourceforge.net/

从 Saxon 文档中:

saxon:discard-document()

saxon:discard-document($doc as document-node()) ==>;文档节点()

此函数从 Saxon 的内部文档池中删除文档。
该文档暂时保留在内存中,但会被
当所有引用都被 Java 垃圾收集器从内存中释放时
文档树中的节点已超出范围。这有
好处是释放内存,但缺点是如果同样
在同一个转换过程中再次加载文档,它将是
从源文本中重新解析,并且不同的节点标识符将被
分配。该函数返回提供为的文档节点
一个参数,允许它在调用中使用,例如
select="saxon:discard-document(document('a.xml'))"。

如果您需要如何使用 saxon:discard-document 的示例,请告诉我,我可以发布一个。

Like user1066037's answer, hopefully you can switch to Saxon. Saxon has an extension called saxon:discard-document. It's available in either the PE or EE editions or Saxon-B. Search for "Saxon-B" here: http://saxon.sourceforge.net/

From the Saxon documentation:

saxon:discard-document()

saxon:discard-document($doc as document-node()) ==> document-node()

This function removes a document from Saxon's internal document pool.
The document remains in memory for the time being, but will be
released from memory by the Java garbage collector when all references
to nodes in the document tree have gone out of scope. This has the
benefit of releasing memory, but the drawback is that if the same
document is loaded again during the same transformation, it will be
reparsed from the source text, and different node identifiers will be
allocated. The function returns the document node that was supplied as
an argument, allowing it to be used in a call such as
select="saxon:discard-document(document('a.xml'))".

If you need an example of how to use saxon:discard-document, let me know and I can post one.

亣腦蒛氧 2024-11-22 16:10:46

您提供的链接包含一个使用自定义处理指令来禁用缓存的示例。您尝试过那里建议的解决方法吗?

The link you provided contains an example using a custom processing instruction to disable caching. Did you try the workaround suggested there?

花期渐远 2024-11-22 16:10:46

如果你有选择的话。

只需将 Xalan 替换为 Saxon,一切都会变得更快,并且您可以显着减少内存消耗。

据我所知,Xalan会将文档加载到内存中,除非最新版本中发生了某些更改。

Saxon 有流模式: http://www.saxonica.com/documentation/ sourcedocs/streaming/streaming-templates.xml

希望有帮助。

If you have a choice.

Just swap Xalan with Saxon and everything will be much faster and you may cut the memory consumption significantly.

From what I know, Xalan will load document into the memory, unless something has been changed in the latest release.

Saxon have streaming mode: http://www.saxonica.com/documentation/sourcedocs/streaming/streaming-templates.xml

Hope that helps.

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