[jdom-interest] Element constructors?

William Krick wkrick at eio-online.com
Thu Jul 24 12:09:32 PDT 2003


Does JDOM have some sort of way to create a new element with content?

I'm envisioning something like...

  Element element = new Element("MYTAG", "some content text");


I looked through the docs and I don't see anything like that.


The alternative is to make helper methods that do the same thing for me...

  Element makeElement(String name, String value){
    Element element = new Element(name);
    element.setText(value);
    return element;
  }

of course, since there's not a Variant type in Java yet (as far as I know),
there would need to be versions for the other basic types...


  Element makeElement(String name, boolean value){
    Element element = new Element(name);
    element.setText(String.valueOf(value));
    return element;
  }

  Element makeElement(String name, int value){
    Element element = new Element(name);
    element.setText(String.valueOf(value));
    return element;
  }

  Element makeElement(String name, float value){
    Element element = new Element(name);
    element.setText(String.valueOf(value));
    return element;
  }




More information about the jdom-interest mailing list