此致 鲍里斯
答案 0 :(得分:6)
将java对象转换为xml的最简单示例是:
@XmlRootElement( name = "entity")
public class Entity {
private int age = 22;
private String firstname = "Michael";
public int getAge() {
return age;
}
public void setAge( int age ) {
this.age = age;
}
public String getFirstname() {
return firstname;
}
public void setFirstname( String firstname ) {
this.firstname = firstname;
}
}
public class Main {
public static void main( String[] args ) {
JAXBContext jc = JAXBContext.newInstance( Entity.class );
Marshaller m = jc.createMarshaller();
m.marshal( new Entity(), System.out );
}
}
将打印到控制台:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><entity><age>22</age><firstname>Michael</firstname></entity>
答案 1 :(得分:0)
答案 2 :(得分:0)
它认为你应该选择JAXB
和JAXP
,这会让你的生活比使用DOM更容易......