格式化Xstream生成的XML [英] Format XML generated by Xstream

查看:383
本文介绍了格式化Xstream生成的XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想格式化Xstream生成的输出XML,使其更具可读性。目前,在每个元素之后添加换行符,但我希望在每个属性之后添加换行符。有没有办法做到这一点?

I want to format the output XML generated by Xstream, to make it more readable. Currently, a newline is added after each element but I would like newline to be added after every attribute. Is there a way to do this?

默认使用Pretty Print Writer来格式化xml的输出,但这对我来说还不够。我希望在每次

Pretty Print Writer is used by default to format the output of the xml but this doesn't suffice for me. I want newline to be added after every

推荐答案

XStream包含 PrettyPrintWriter

XStream includes a PrettyPrintWriter

构建XStream之后......

After building your XStream...

XStream xstream = //...whatever

而不是:

// p is my object needing xml serialization
xstream.toXML(p)

使用类似的东西使它漂亮:

Use something like this to make it pretty:

BufferedOutputStream stdout = new BufferedOutputStream(System.out);
xstream.marshal(p, new PrettyPrintWriter(new OutputStreamWriter(stdout)));

这篇关于格式化Xstream生成的XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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