[jdom-interest] Element.SetChildren question
Jason Hunter
jhunter at collab.net
Mon Dec 18 09:24:28 PST 2000
Bug. I have an XXX in the code already regarding this.
-jh-
Bernard D'Have wrote:
>
> 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
>
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com
More information about the jdom-interest
mailing list