Reputation: 111
Regards, Boris
Upvotes: 4
Views: 7206
Reputation: 33534
It think you should go with JAXB
and JAXP
, this will make your life much easier than using DOM.....
Upvotes: 0
Reputation: 185
Simplest example of convert java object to xml is this:
@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 );
}
}
Will print to the console this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><entity><age>22</age><firstname>Michael</firstname></entity>
Upvotes: 6