JDOM copy element without content

Hi!

I like to copy an element X from an (input) JDOM document to become the root element of a new (output) JDOM document. I can do that. so far so good. Only the input JDOM I'm touching is quite lange and from the element to copy, the complete content (many other elements) gets copied aswell. But I need to copy just the start tag with it's attributes and the end tag. like:

Input JDOM

<Y>

<X abc="123" def="456">

<A xyz="234">

InhaltVonA

</A>

<B>

<C www="http"/>

</B>

</X>

</Y>

Output JDOM

<X abc="123" def="456">

</X>

How can I do that?

Cheers,

Marcello, Germany

[796 byte] By [MarcelloBonventrea] at [2007-11-26 18:10:28]
# 1

.removeContent is the one to be known..

SAXBuilder builder = new SAXBuilder();

File f = new File("xml.xml");

Document doc = builder.build(f);

// get the root element

Element rootElement = doc.getRootElement();

// get the X element

Element xElement = rootElement.getChild("X");

//clone the X element and remove all

// children

Element copyOfX = (Element)(xElement.clone());

copyOfX.removeContent();

// create a new document with the x element

Document doc2 = new Document(copyOfX);

MarcelloBonventrea at 2007-7-9 5:42:48 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...