[jdom-interest] create xml tree

Mikael Petterson (KI/EAB) mikael.petterson at ericsson.com
Mon Feb 2 05:59:23 PST 2004


Sorry for not being very clear on what I want to do. I give it another try.

I import an xml file (1). I creat a JDOM tree and retrieve information about parent-child relations since the xml I have does not express that for my objects explicitly. Then I have to create an another xml file (2) that describes the relationship between the objects. I have to create xml (2) to look like this:


This describes that parent-child relation in xml. Which is fine. But when I extract the relationship and try to build xml (2) I get a problem with keeping the relations.

I addContent() to rootObject. Like this:


Will the resulting Element be rootObject+ObjectA.
So how can I then add ObjectB?

Hope it is a little bit more clear :-) Maybe ....



-----Original Message-----
From: Per Norrman [mailto:pernorrman at telia.com]
Sent: den 2 februari 2004 13:57
To: Mikael Petterson (KI/EAB); jdom-interest at jdom.org
Subject: SV: [jdom-interest] create xml tree


this one was hard to understand ...

> I am trying to find out if there is a way of adding children 
> in a way that the parent-child relation will be kept.

When you add one element (child) to another element (parent),
you create a parent-child relationship. Which parent-child
relationship do you want to be preserved?

> I have a method to create the relation inbetween parent and 
> child. I then want to make a recursive add of 
> children to each parent. I have about 8 levels of 
> parent-child relations. Doing 
> parent.addContent(child); 
> seems only to add the first level. How can I make it recursive?

You cannot make it recursive! Where are the grand children, and the
grand-grand children, etc?

> Do I have to keep track of the element that I start to add 
> children to and when all my addContent have been done I add 
> the first element to the root and last create a Document?

Not knowing what your'e trying to do, but here are two hints:

1) if youre tree is static, one alternative is to use a bottom-up
approach (although I do not really recommend the coding style):

    Element e =
       new Element("L1").addContent(
         new Element("L2").addContent(
            new Element("L3").addContent(
               new Element("L4").addContent(
                  new Element("L5").addContent(
                     new Element("L6").addContent(
                        new Element("L7").addContent(
                           new Element("L8"))))))));

(At least the tree structure is obvious :-))

2) if your tree is dynamic, you must have some representation of it
you go off and construct the JDOM tree. This representation must then be
and the JDOM tree built up along the way.


This communication is confidential and intended solely for the addressee(s). Any unauthorized review, use, disclosure or distribution is prohibited. If you believe this message has been sent to you in error, please notify the sender by replying to this transmission and delete the message without disclosing it. Thank you.

E-mail including attachments is susceptible to data corruption, interruption, unauthorized amendment, tampering and viruses, and we only send and receive e-mails on the basis that we are not liable for any such corruption, interception, amendment, tampering or viruses or any consequences thereof.

More information about the jdom-interest mailing list