[jdom-interest] detach() [eg]

philip.nelson at omniresources.com philip.nelson at omniresources.com
Wed Apr 25 09:19:02 PDT 2001


> The only problem is that 1 and 2 don't make sense if used together.
>

You losing me here!  Perhaps you're missing the point the the exception will
normally never get thrown because you will either dispose of the Document or
set the root element. 

Except for Document, the changes needed would be to remove the detach from
element.

Element.removeContent(Element) does exactly what we need.  Copy (with clone
works as now)

//NOW - get an element to detach
Element elToDetach = someElement.getChild("elToDetach");
elToDetach.detach();

would be replaced by 
//NEW - get an element to detach
Element elToDetach = someElement.getChild("elToDetach");
someElement.removeContent(elToDetach);

For a rootElement
//get an element to detach
Element elToDetach = doc.getRootElement();
doc.detach(elToDetach);

or maybe even better
Element elToDetach = doc.removeRootElement();


> Also 2 won't work because 2 child elements could be identical 
> so how to
> differentiate ?

Object == just as it works now.

> 
> Perhaps you should go back to coding and let the expert 
> (bickerers) carry on
> arguing ;-)

Probably, but I just can't seem to get enough.

> 1 - detach becomes the responsibility of the parent and takes 
> an argument of
> the content to be detached.
> 2 - detaching a root element from document will put the 
> document into an
> illegal state and the IllegalStateException will be thrown by 
> getRootElement
> and getMixedContent
> 3 - after the root element is detached, it will internally be 
> set to null.



More information about the jdom-interest mailing list