Java:IndentingXMLStreamWriter替代? [英] Java: IndentingXMLStreamWriter alternative?

查看:133
本文介绍了Java:IndentingXMLStreamWriter替代?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用StAX创建一个非常大的xml文档。到目前为止,我使用IndentingXMLStreamwriter类来获取格式良好的文档(另请参阅 this回答)。几天前,我们设置了一个jenkins服务器,它有一个较旧的jdk版本(6.26),我得到了构建错误。

I am using StAX to create a quite large xml document. Until now I was using the IndentingXMLStreamwriter class to get a well formatted document (see also this answer). A few days ago we setup a jenkins server with an older jdk version (6.26), on which i get build errors.

package com.sun.xml.internal.txw2.output does not exist

我认为由于安装了jdk版本,无法找到包。由于不同的原因,这不能改变
(顺便说一下,有没有人知道jdk版本,这个包(com.sun.xml.internal.txw2.output)被添加了?)。$
因此我正在寻找缩进的替代方案。我更喜欢与我使用的解决方案类似的解决方案,这意味着无需重新分析文档。有什么想法或建议吗?

I assume the package cannot be found because of the installed jdk version. For different reasons this cannot be changed (by the way, does anyone know the jdk version, at which this package (com.sun.xml.internal.txw2.output) was added?).
Therefore I am looking for an alternative to do the indenting. I would prefer a solution similar to the one I was using, which means without reparsing the document. Any ideas or suggestions?

谢谢

Lars

Thanks
Lars

推荐答案

如果其他建议不起作用,您可以从Saxon获得一个缩进的XMLStreamWriter,如下所示:

If other suggestions don't work, you can get an indenting XMLStreamWriter from Saxon like this:

Processor p = new net.sf.saxon.s9api.Processor();
Serializer s = p.newSerializer();
s.setOutputProperty(Property.METHOD, "xml");
s.setOutputProperty(Property.INDENT, "yes");
s.setOutputStream(....);
XMLStreamWriter writer = s.getXMLStreamWriter();

一个优点是,这允许您使用其他序列化属性对序列化进行大量控制。

One advantage is that this allows you a lot of control over the serialization using other serialization properties.

这篇关于Java:IndentingXMLStreamWriter替代?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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