Better late than never .... ;-)

----- Original Message -----
From: "A Yang" <[EMAIL PROTECTED]>
> Hello,
>
> From going through the mailing list archives, it seems
> that the recommended way of merging one dom4j tree
> into another is to detach() the root node of one and
> use addElement() to graft it onto the other.
>
> However, I got this to work first using
> Element.appendContent() which seems to work fine - I
> appear to have successfully inserted an entire
> hierarchy of nodes.
>
> Is there a rule of thumb over when it is best to use
> either detach and addElement, versus appendContent?

detach() is the best & most efficient approach. It all boils down to do you
want to create new nodes or reuse old ones and save the construction.

addElement() will always create new nodes. appendContent() is OK if you want
to append the content of one Element to another but will also result in node
creation.


> And is there going to be a helper method for adding a
> bit of static xml a la "<someTag><otherTag>text
> content</otherTag></someTag>"? Although wouldn't you
> just be able to use a StringSource?

How about this...

String xml = "<someTag>...</someTag>";
Document doc = DocumentHelper.parseText( xml );

// add <someTag> to a new destination
Element destination = ...;
destination.add( doc.getRootElement().detach() );

James


_________________________________________________________
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