Hi Kerstin

From: "Kerstin Gr�nefeld" <[EMAIL PROTECTED]>
> I have some questions concerning documents.
>
> 1. How can merge two documents, if both documents have elements with the
> same name
> on the same level?
> Is there a possibility to avoid the IllegalAddException ?
> Is there some kind of automatism?

If you wish to add the content of one document to another you can either
perform a deep clone, via the clone() method (or createCopy() methods on
Element).

Or if you want to remove content from one document and add it to another,
you can detach it from one document using the detach() method first before
adding it to the other.

e.g.

SAXReader reader = new SAXReader();
Document doc1 = reader.read( "foo.xml" );
Document doc2 = reader.read( "bar.xml" );
Element root1 = doc1.getRootElement();
Element root2 = doc2.getRootElement();
root2.detach();
root1.add( root2 );

This will add the root element of of doc2 to the root element of doc2. This
can happen on any node, though remember that a document can only contain one
root element.

If you wish to add both root elements as siblings then you could do...

Element root1 = doc1.getRootElement();
Element root2 = doc2.getRootElement();
root1.detach();
root2.detach();
Element newRoot = doc1.addElement( "root" );
newRoot.add( root1 );
newRoot.add( root2 );


> 2. I have an document created with
>   document = IndexedDocumentFactory.getInstance().createDocument();
>   then I append some elements and after this I want to search for nodes:
>
>    List list = document.selectNodes( "//test/testelement" );
>
>    I always get a the follwing Exception:

Whoops - looks like you've found a bug - sorry about that.

I'll look into it shortly and send out a mail when I've patched the code, it
should be quite an easy fix by the look of things.  Thanks for findiing this
bug.

James


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


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

Reply via email to