如何在简单的 XML 中转换 Java Bean。我需要一个用于 alla 对象的标准方法。
例如:
public Class Customers {
public Class Person {
private String name;
public String getName() {
return this.name;
}
public String setName(newName) {
this.name = newName;
}
} //end Person class
public String getPerson() {
return this.Person;
}
public String setName(newPerson) {
this.Person = newPerson;
}
} //end Customers class
实例化:
Customers customers = new Customers();
Person person = new Person();
person.setName("Siegfried");
customers.setPerson(person);
System.out.print(beanToXml(customers));
XML 输出:
<Customers>
<Person>
<name>Siegfried</name>
</Person>
</Customers>