[jdom-interest] Merging jdoms

Ken Rune Helland kenh at csc.no
Wed May 9 01:05:13 PDT 2001


At 08:09 AM 5/9/2001 +0100, Heather Boyd wrote:


>Thanks for your suggestion.
>
>I also found that this worked :
>
>
>          Document doc = new Document(new Element("NEW"));
>          Element root = doc.getRootElement();
>
>          Document doca =  JDomFromAnOtherSource();
>          Element a = doc.getRootElement();
>          root.addContent((Element) a.clone());
>
>
>I couldn't find detach() in the javadoc (jdomb6). But I imagine its a better
>solution because it's designed for this purpose.
>

It does someting different.  If you use the a.clone() metod
you create a clone/copy iof the "a" element, if "a" is big this
both takes time and consumes memory. But on the pluss side
the "doca" document is still intakt after the clone.

a.detach() on the other hand removes "a" from "doca" leaving
"doca" in a invalid state by stealing its root element.

So if you need to keep "doca" in its current state use a.clone()
if you are going to trow away "doca" use a.detach() for better
performace both in space and time.


KenR



>Heather Boyd wrote:
> >
> > I have three small jdoms (all different) and would like to create a new
>jdom
> > from them, but keep them intact.
> > In otherwords the old jdoms are copied exactly, and their root Element is
> > added to the root Element
> > of the new jdom.
> >
> > Is there an easy way to do this, ie, I though something like this would
>work
> > but it
> > didn't.
> >
> > Document doc = new Document(new Element ("NEW"));
> > Element root = doc.getRootElement();
> >
> > Document doca =  JDomFromAnOtherSource()
> > Element a = doc.getRootElement();
> > root.addContent(a)
>
>Call a.detach() to remove "a" from its document before adding it to
>another document.
>
>-jh-
>_______________________________________________
>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