我想用Xstream序列化对象的ArrayList。它工作,但整个输出写在一行。我的代码如下所示:
XStream xstream = new XStream(new StaxDriver());
String target = fc.saveFile("xml", "Choose where to save your events");
if (!target.contains(".xml"))
target += ".xml";
try (FileWriter fw = new FileWriter(target)) {
xstream.toXML(FooList.getFooList(), fw); //// this returns an ArrayList<Foo>
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
输出如下:
<?xml version="1.0" ?><list><foo><id>0</id> [...] </foo></list>
一切都写在一行。知道怎么改变这个吗?我只想要一个标准格式,如:
<list>
<id>
....
答案 0 :(得分:0)
好的答案了......问题是
XStream xstream = new XStream(new StaxDriver());
应该是
XStream xstream = new XStream(new DomDriver());