[jdom-interest] Merging a root element into another document

Bradley S. Huffman hip at cs.okstate.edu
Sun Aug 24 18:01:20 PDT 2003


Tim Sutton writes:

> I am trying to merge several jdom documents together:
> 
>       org.jdom.Element myRootElement =3D new org.jdom.Element("MasterDocume=
> nt");
>       //toplevel xml element
>       org.jdom.Document myDocument =3D new org.jdom.Document(myRootElement);
>       //get the document to be merged in
>       Document myDocument =3D childDocument.toDom();
>       //add child document record element to document root
>       myRootElement.addContent(myDocument.getRootElement());

Detach the old root from it's parent, as in

        myRootElement.addContent(myDocument.detachRootElement());

Brad



More information about the jdom-interest mailing list