[jdom-interest] Class generator

Rolf jdom at tuis.net
Wed Dec 21 18:26:25 PST 2011

Hi Alexandre.

Thank you for your feedback. It's nice when people respond the way you have.

I have some observations, and a question....

First the questions, in an earlier mail you indicated that you are using 
Java 1.2.1. Do you have this running under Java 1.2.1? Are you using 
JDOM 1.1.2?

Then the observations....

Just out of interest (and I know that the 'cars2java' example may be a 
massive simplification), but have you considered simply extending the 
JDOM classes to get what you want? You may be able to eliminate a 
complex 'model'. It may create other issues, but, you may come up with a 
simpler (and perhaps better) solution.

For example, you could declare the class 'Car' to be:

public class Car extends org.jdom.Element {

     public Car(String brandname) {

     public void setBrand(String brandname) {
         Element brand = getChild("Brand");
         if (brand == null) {
             brand = new Element("Brand");
             // add brand at the beginning of our content....
             addContent(0, brand);

     public String getBrand() {
         Element brand = getChild("Brand");
         if (brand == null) {
             return "";
         return brand.getText();



Once you have defined 'Car' to extend the JDOM Element, you can create 
Car instances, and add them directly to a root element:

Element cars = new Element("Cars");
Car renault = new Car("renault");
renault.setColorRGB("red", "FF0000");

xmlout.output(System.out, cars);

Just some thoughts.


On 21/12/2011 6:05 PM, Alexandre Santos wrote:
> Hello Rolf,
> I've been doing some experiments with a software called EditiX that can
> creates Java classes from a XML file. I've used JDOM on those classes to
> accomplish what I've been trying.
> The description of the solution I've figured out is here:
> www.alexandre-santos.com/Cars2Java.html
> <http://www.alexandre-santos.com/Cars2Java.html>
> Alexandre

More information about the jdom-interest mailing list