简体   繁体   English

如何使用XStream缩进XML?

[英]How to indent XML with XStream?

I would like to be able to set the indentation to a number of spaces when storing with XStream. 使用XStream存储时,我希望能够将缩进设置为多个空格。 I have seen this SO post and I'm afraid it's not quite clear how to set the number of spaces to use. 我已经看过这篇SO帖子,而且恐怕还不太清楚如何设置要使用的空格数。 I seem to not be getting something. 我似乎没有得到任何东西。 Could somebody kindly explain this and illustrate it with an example? 有人可以解释一下并举例说明吗?

Following the example in the post you've linked to and the API , I came up with this code: 按照您链接到的帖子和API中的示例,我想到了以下代码:

char[] indent = new char[] { ' ', ' ', ' ', ' ' };
BufferedOutputStream stdout = new BufferedOutputStream(System.out);
xstream.marshal(object, new PrettyPrintWriter(new OutputStreamWriter(stdout), indent));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM