[jdom-interest] detach() [eg]

Elliotte Rusty Harold elharo at metalab.unc.edu
Tue Apr 24 10:48:48 PDT 2001

At 9:37 PM -0500 4/23/01, philip.nelson at omniresources.com wrote:

>Actually, so do I.  As least there is no hidden side effects.  The change
>would be fairly minor too because you would only have to do it where there
>are possilbe child elements.  But swaying the argument about the Document
>detaching the root element has been quietly passed on by Elliotte.  I guess
>you would have to clone the root element to copy it exactly somewhere else.

You have to clone the root element anyway if you want COPY the root 
element. However, if you merely want to MOVE the root element then 
the code is simple.

Element oldRoot = oldDocument.getRootElement();
Document newDocument = new Document(oldRoot);

The second line above should detach the old root element. In fact it 
should be doing it now, and I just looked at the code and it does.

| Elliotte Rusty Harold | elharo at metalab.unc.edu | Writer/Programmer |
|                  The XML Bible (IDG Books, 1999)                   |
|              http://metalab.unc.edu/xml/books/bible/               |
|   http://www.amazon.com/exec/obidos/ISBN=0764532367/cafeaulaitA/   |
|  Read Cafe au Lait for Java News:  http://metalab.unc.edu/javafaq/ |
|  Read Cafe con Leche for XML News: http://metalab.unc.edu/xml/     |

More information about the jdom-interest mailing list