[jdom-interest] Merging jdoms

Heather Boyd hlb at aspectgroup.co.uk
Wed May 9 00:09:08 PDT 2001


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.


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-



More information about the jdom-interest mailing list