Sounds a bit like an exam question ;-)

Remember that the Element.content() returns a List of Node objects that you
can change and that Node has getParent() to walk up the tree. So once you've
found car3 there are various ways to do what you need. e.g.

Element car3 = (Element) doc.selectSingleNode( "doc1/red/small/car3" );
Document doc2 = ...;
Element red = (Element) doc2.selectSingleNode( "doc2/red" );
Element small = red.addElement( "small" );
small.add( car3.detach() );

James
----- Original Message -----
From: "WERKSTUDENT1" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, January 23, 2002 2:42 PM
Subject: [dom4j-user] mergind documents


> Hi again!
> Another question related with my last mail:
>
> Imagine again:
>
> doc1
>   -----red
>          -----large
>                 -----car1
>                 -----car2
>          -----small
>                 -----car3
>   -----blue
>          -----large
>                 -----car4
>
> Is there a way to extract the path of the document for only one element?
For
> example I'd like to get the tree to "car3":
>
> doc1
>   -----red
>          -----small
>                 -----car3
>
> Now it should be possible to enter this tree into another document which
> looks like:
>
> doc2
>   -----red
>          -----large
>                 -----car9
>
> to get the final combined document:
>
> doc1
>   -----red
>          -----large
>                 -----car1
>          -----small
>                 -----car3
>
>
> Guess what I'd like to do? It's the same in my last post, but a liitle
more
> step by step, so that I check if one Element is already existing in
another
> tree and if not enter it, otherwise do something else for example change
the
> value of the original tree.
>
> Rgds.
> Marc
>
> _______________________________________________
> dom4j-user mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/dom4j-user


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


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

Reply via email to