日期:2014-05-20  浏览次数:20687 次

空list对象生成xml文件
Java code

public class Person {
    private String name;
    private int height;
}
public class ListPerson {
    private List<Person> list;
}


我使用XStream生成xml字符串,如果获得结果集数据为null,那么生成的字符串为<ListPerson/>,这种情况对方就不能解析出是节点是什么,所以我需要得到的字符串为
<ListPerson>
<name></name>
<height><height>
</ListPerson>
大家有什么好的方法(除拼串之外),有没有其他的xml生成包能达到这种要求

------解决方案--------------------
你new个Person丢到List里不就好了 Person不赋值
没有那个xml包能读懂你的意念给你产生个Person对象。。
------解决方案--------------------
给默认值 null
------解决方案--------------------
探讨

引用:

你new个Person丢到List里不就好了 Person不赋值
没有那个xml包能读懂你的意念给你产生个Person对象。。

如果我new一个空的对象,那么得到的结果是
XML code

<ListPerson>
<Person/>
</ListPerson>


如果我想得到下列的格式,就是把字段值也列举出来如何处理?
XML code……

------解决方案--------------------
Java code

public class Person {
    private String name;
    private int height;
}
public class ListPerson {
    private List<Person> list;
}


我使用XStream生成xml字符串,如果获得结果集数据为null,那么生成的字符串为<ListPerson/>,这种情况对方就不能解析出是节点是什么,所以我需要得到的字符串为
<ListPerson>
<name></name>
<height><height>
</ListPerson>
大家有什么好的方法(除拼串之外),有没有其他的xml生成包能达到这种要求