[jdom-interest] Moving Children
Kevin Baynes
kbaynes at seagullsw.com
Thu Jun 7 12:05:59 PDT 2001
I have two nodes that have children. I would like to take all the children
from one node and move them to the other. Is there a way to do this
*without* looping through each of the children to move and calling
Element.detach() ?
I first wrote it like this, but caught myself before compiling:
groupOne.getChild("users").setMixedContent(
groupTwo.getChild("users").getChildren() );
I got to the end and wanted to just add .detach() to the getChildren()
method, but that's a JDOM method, not a List method. :-)
Question: The above code will generate an error because all of the children
of groupTwo already have a parent, correct?
Question: Is there a way to harvest the List of children from groupTwo so
that they are detached from the parent, so that the above code will work?
Must I instead do it like so:
Iterator it = groupTwo.getChild("users").getChildren().iterator();
Element elt;
while ( it.hasNext() ) {
elt = (Element)it.next();
groupOne.getChild("users").addContent( elt.detach() );
}
Thanks!! :-)
--------------------
Kevin Baynes
Software Engineer
kbaynes at seagullsw.com
703-393-2191
More information about the jdom-interest
mailing list