Format XML generated by Xstream

匿名 (未验证) 提交于 2019-12-03 01:41:02

问题:

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 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

回答1:

XStream includes a PrettyPrintWriter

After building your XStream...

XStream xstream = //...whatever 

Instead of:

// 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))); 


回答2:

Take a look at their tutorial on tweaking the output.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!