[jdom-interest] Element.SetChildren question

Bernard D'Have bdha at SpiritSystems.be
Mon Dec 18 01:38:22 PST 2000


First, many thanks for JDOM api!
I'm very happy to manipulates XML documents with a java point of view.

But, I have a question: if I have a List with several elements, I can set
another element by at least two ways
A) by looping on the list and addContent method like this:
  public void test1() {
    Document doc= new Document(new Element("root"));
    List l= elements();
    for (int i= 0; i<l.size(); i++) {
      doc.getRootElement().addContent((Element)l.get(i));
    }
    System.out.println("Test1");
    list(doc);
  }

B) by setChildren
  public void test2() {
    Document doc= new Document(new Element("root"));
    doc.getRootElement().setChildren(elements());
    System.out.println("Test2");
    list(doc);
  }

But the results are not the same:

Test1
Doc:[Document:  No DOCTYPE declaration. Root - [Element: <root/>]]
Root:[Element: <root/>]
Childs: one, parent=[Element: <root/>], doc=[Document:  No DOCTYPE
declaration. Root - [Element: <root/>]]
two, parent=[Element: <root/>], doc=[Document:  No DOCTYPE declaration.
Root - [Element: <root/>]]

Test2
Doc:[Document:  No DOCTYPE declaration. Root - [Element: <root/>]]
Root:[Element: <root/>]
Childs:
one, parent=null, doc=null
two, parent=null, doc=null


If I use the B) alternative, which is much natural, the parent and document
are null!

My question: is this a bug or a misundrstand from my part?

Bernard D'Havé
Software engineer




More information about the jdom-interest mailing list