>Hello,
>
>From going through the mailing list archives, it seems
>that the recommended way of merging one dom4j tree as
>a sub-tree of 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?

appendContent(Branch b) is the same as addAll( Collection c ) in Collection
API. So I adds a complete Brach of Elements into the tree. addElement adds a
single element (and its children of course). From that view both methods do
the same. Note that detach() kills all the parental relations. Unfortunally
I'm not so deep into org.dom4j.Brach to insure that he kills such realtions
automatically are never have them. You should check this.

>And is there going to be a helper method for adding a
>bit of static xml a la "<someTag><otherTag>text
>content</otherTag></someTag>"?

You can do it using 2 lines of code:

Document newDocument = DocumentHelper.parseString("<someTag><otherTag>text
>content</otherTag></someTag>");
oldDocument.getRootElement().addElement(
newDocument.getRootElement().detach() );

Using a parser here is a secure mechanism, because only well formed xml is
used to build
a new dom4j Tree.

> Although wouldn't you
>just be able to use a StringSource?

Not really. But maybe org.dom4j.io.DocumentSource which is based on
SAXSource helpes you ???? :-)

>Thanks,
>Andy

Hope that helps.

Bye
Toby

-- 
GMX - Die Kommunikationsplattform im Internet.
http://www.gmx.net


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

Reply via email to