增量/流式XSLT转换? [英] Incremental/streaming XSLT transformations?

查看:140
本文介绍了增量/流式XSLT转换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通常在JDK(JDK 7)中使用XSLT支持进行XSLT转换。最近我遇到了一个相当大的XML文档,并且对此应用XSLT转换(甚至是非常基本的转换)会导致大量内存被使用。

I'm normally using the XSLT support in the JDK (JDK 7) for XSLT transformations. Recently I've come across a rather large XML document, and applying XSLT transformations to this (even very basic ones) causes a lot of memory to be used.

I'我一直小心翼翼地完成所有处理流程,但看起来JDK中的XSLT引擎(似乎是一个修改过的Xalan)总是首先在内存中构建一个DOM。显然这不是我想要的。

I've been careful to do all my processing streaming, but it seems the XSLT engine in the JDK (which appears to be a modified Xalan) always builds up a DOM in memory first. Obviously this is not what I want.

现在我发现单独提供的Xalan(2007年为2.7.1!)确实有一个用于进行增量转换的API 。因此,虽然这似乎有效,但我实际上希望我的代码在股票JDK上运行,而不会告诉用户摆弄任何背书文件夹。

Now I found out that the Xalan which is available separately (2.7.1 from 2007!) does have an API for doing incremental transformations. So while this does seem to work, I actually want my code to run on a stock JDK, without telling the user to fiddle with any endorsed folder.

什么是最好的在Java中进行增量XSLT转换的方法,以便我的代码与未修改/库存JDK安装兼容?

What is the best way to do incremental XSLT transformations in Java so that my code is compatible with unmodified/stock JDK installations?

更新:
这个最近更新的问题密切相关: 什么是最高效的基于Java的流式XSLT处理器?

推荐答案

首先,我强烈建议使用Apache版本的Xalan和Xerces,而不是捆绑在JDK,这是非常错误的。对于Xerces来说尤其如此。

Firstly, I would strongly recommend using the Apache versions of Xalan and Xerces rather than the versions bundled in the JDK, which are very buggy. That's particularly true for Xerces.

其次,如果您使用的是Java,那么您真的应该转向XSLT 2.0,这样可以大大提高开发效率。在实践中,这意味着Saxon(Saxon的主页版本是免费的)。

Secondly, if you're using Java then you really ought to be moving to XSLT 2.0, which gives you vast improvements in development productivity. In practice that means Saxon (the home edition of Saxon is free).

Xalan中的增量转换实际上并没有阻止它将整个源文档构建为内存中的树;它所做的就是允许树与转换过程并行构建。如果您想要流式转换,Saxon-EE是您唯一的实用选择。 (请注意,saxon:stream()扩展只是Saxon提供的流功能的一小部分。)

Incremental transformation in Xalan doesn't actually stop it building the whole source document as a tree in memory; all it does is to allow the tree to be built in parallel with the transformation process. If you want a streaming transformation, Saxon-EE is your only practical option. (Note that the saxon:stream() extension is only one small part of the streaming capabilities that Saxon offers).

这篇关于增量/流式XSLT转换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆