[jdom-interest] Moving Subtrees using JDOM

Jason Hunter jhunter at acm.org
Fri Feb 22 11:26:34 PST 2002

Elliotte Rusty Harold wrote:
> At 10:12 AM -0800 2/22/02, Jason Hunter wrote:
> >An element retains its children when it's moved, so I don't know what
> >problem you could be having.  Just detach the element from its own
> >parent and splice it somewhere else, and all its children will tag along
> >for the ride.
> >
> I think what he's asking for is something more akin to
> DocumentFragfment in DOM; i.e. he doesn't want to move an Element. He
> wants to move a sequence of three elements, two text nodes, a
> comment, and perhaps a few more text nodes. You might be able to do
> this using Lists. I'm not sure.
> OK, I just looked at the JavaDoc and I don't think we can do that, at
> least not in the most general case. I think what we'd need would be
> an addContent(List) method. We have setContent(List) but not
> addContent(list). You could do it in two steps by retrieving the
> content of the element you wanted to put it in with getContent() and
> then using the methods of the List interface.

Kind of like:


Except the content being moved will have parents so this won't work
exactly.  You'll have to iterate over them and detach each before the
move.  Might as well just set up an iterator and do a detach/add for
each right there.


More information about the jdom-interest mailing list