----- Original Message -----
From: "Lea Allison" <[EMAIL PROTECTED]>
> Great, it seems to be working. But the problem I now have is that the
> original Document tree is deleted?
>
> I guess the .detach() part is removing it after copying it over? Is there
> anyway to keep the original Document untouched?

If you want to keep a copy of the original document untouched but add a copy
of its content to another document then there are 2 ways to create a copy.
Firstly Node implements Cloneable so all dom4j nodes are cloneable() which
will detach the clone from its parent. Or for Elements you can use the
typesafe createCopy() which can be used to rename an element fragment if
required...

e.g.

> SAXReader reader = new SAXReader();
> Document doc1 = reader.read( "foo.xml" );
> Document doc2 = reader.read( "bar.xml" );
>
> // lets add the root element of doc2 to the root of doc1
> // remember an XML document can only have one root
>
> Element root1 = doc1.getRootElement();
> Element root2 = doc2.getRootElement();
> root1.add( root2.detach() );

root1.add( root2.createCopy() );

or if you want to change the root element name...

root1.add( root2.createCopy( "newName" ) );

James



_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to