[jdom-interest] elt.detach()
Jason Hunter
jhunter at collab.net
Wed Dec 27 22:38:48 PST 2000
Hi,
I believe it would be useful to have an element.detach() method that
removes an element from its parent (if there is a parent), and returns
the detached element afterward. This simplifies the act of moving an
element to a new location from this right now:
if (kid.getParent() != null) {
kid.getParent().removeContent(kid);
}
if (kid.getDocument() != null) {
// see later discussion
}
newParent.addContent(kid);
to simply:
newParent.addContent(kid.detach())
The only tricky thing is what to do if the Element being "detached" is a
root element, as shown above. Technically just removing a root elt from
its document makes the document no longer well-formed. So perhaps we
could do something like oldDoc.setRootElement(new
Element("placeholder"))?
Ideas?
-jh-
More information about the jdom-interest
mailing list