[jdom-interest] detach() [eg]

Kenworthy, Edward edward.kenworthy at exchange.co.uk
Wed Apr 25 23:44:42 PDT 2001


No I think you're missing the point. Tell me, if detach is on the parent how
could you ever remove the root ? Therefore cases 2 and 3 never occur.

-----Original Message-----
From: philip.nelson at omniresources.com
[mailto:philip.nelson at omniresources.com]
Sent: 25 April 2001 17:19
To: jdom-interest at jdom.org
Subject: RE: [jdom-interest] detach() [eg]


> 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.
_______________________________________________
To control your jdom-interest membership:
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhos
t.com



More information about the jdom-interest mailing list