[jdom-interest] create xml tree

Phil Weighill-Smith phil.weighill-smith at volantis.com
Mon Feb 2 06:14:23 PST 2004

The result of:


is to set rootObject as the parent of objectA and to add objectA into
the content of rootObject such that rootObject.getContent() will return
a list that contains an objectA reference within it
(rootObject.getContent().indexOf(objectA) will return a 0 or positive
value). This assumes that objectA doesn't yet have a parent!

To add ObjectB to ObjectA you must:


Again objectB must not yet have a parent.

As Per said, you need to build your JDOM from whatever other
representation you already have in memory using whatever logic your
application needs!

I still don't understand where the problem is, but that's probably
because I've no idea what you're really trying to achieve!

Phil :n)

On Mon, 2004-02-02 at 13:59, Mikael Petterson (KI/EAB) wrote:

> Hi,
> 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:
> <Model>
>  <RootObject>
>   <ObjectA>
>    <ObjectB/>
>    <ObjectC/>
>    <ObjectD>
>     <ObjectE/>
>    </ObjectD>
>   </ObjectA>
>  <RootObject>
> </Model>
> 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:
> rootObject.addContent(ObjectA);
> Will the resulting Element be rootObject+ObjectA.
> So how can I then add ObjectB?
> Hope it is a little bit more clear :-) Maybe ....
> BR
> //Mikael
> -----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
> Sorry,
> 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
> before
> you go off and construct the JDOM tree. This representation must then be
> traversed
> and the JDOM tree built up along the way.
> /pmn
> 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.
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com

Phil Weighill-Smith <phil.weighill-smith at volantis.com>
Volantis Systems
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://jdom.org/pipermail/jdom-interest/attachments/20040202/dd472c10/attachment.htm

More information about the jdom-interest mailing list