[jdom-interest] JDOM Elements from simple Java data objects

Dennis Sosnoski dms at sosnoski.com
Mon Jul 12 19:02:34 PDT 2004

The type of application you're describing can be done much more easily 
with an XML data binding tool, rather than JDOM - the whole point of 
data binding is to convert Java objects to and from XML. My own JiBX 
framework (http://www.jibx.org) is probably the best choice for this 
case, where you want to work with existing objects. You could also do 
this with Castor, but JiBX is much faster and considerably more flexible 
in terms of the data structures.

If you really need the result in JDOM, you're probably still best off 
generating it using data binding and then parsing it to construct a JDOM 
representation. You could also use a builder that hooks up to Castor or 
JiBX, but I don't think either framework has one of this type right now 
(JiBX doesn't, anyway).

  - Dennis

William BC Crandall wrote:

>Hello JDOMers,
>I'm using Hibernate to get simple data objects out of a DB.
>Is there an existing tool to turn such get/set objects into
>JDOM Elements with the same structure? 
>That is, somthing that would generate an address element:
>  <id></id>  <!-- using toString -->
>  <street></street>
>  <city></city>
>given an object of the class:
>public class Address implements Serializable {
>  private Integer id;
>  private String street;
>  private String city;
>  public Address() {
>  }
>  public Integer getId() {
>    return id;
>  }
>  public void setId(Integer newId) {
>    this.id = newId;
>  }
>  public String getStreet() {
>    return street;
>  }
>  public void setStreet(String newStreet) {
>    this.street = newStreet;
>  }
>  public String getCity() {
>    return city;
>  }
>  public void setCity(String newCity) {
>    this.city = newCity;
>  }
>I know this can be done "by hand," with a series of Element, 
>new Element(); setText(); addContent(); statements, but was
>looking for something a bit more automatic.
>I can't believe I'm the first to want to do this, but I've not
>found any references in the FAQ, mail archives, or with Google.
>Many thanks for any suggestions.
>Best to all,
>William BC Crandall
>bc.crandall [around] earthlink.net

More information about the jdom-interest mailing list