[jdom-interest] Problem with 'setChildren' on JDOM B8

duncan.loveday at bt.com duncan.loveday at bt.com
Mon Dec 9 02:00:02 PST 2002


Jason,

Thanks for this. A couple of observations

(1) I get no deprecation warnings for setChildren() on compilation and don't
see it as deprecated at
http://www.jdom.org/docs/apidocs/org/jdom/Element.html#setChildren(java.util
.List)

(2) It makes perfect sense for setChildren() to only clear previous element
content and setContent() to clear all previous content. However, the javadoc
for setChildren() at the above URL states

"This sets the content of the element the same as
setContent(java.util.List), except only Element objects are allowed in the
supplied list. "

which I would say is misleading given that setChildren() does not clear text
content whereas setContent() does.

(3) What you suggest would equate in my case to

elem.setContent(elem.getChildren());

but this clears both text and element content because of the "live" List
returned by getChildren(). When 'setContent()' clears the old content, it
also clears the new content it is about to replace it with. It might be nice
to have the option to obtain "non-live" Lists that provide a static snapshot
of the content.

(4) I would suggest it might also be nice to have methods to clear specific
types of content. For example

    public void removeText()
    {
        // Remove all text content but preserve other content children....
        List textContent=this.getContent(new
ContentFilter(ContentFilter.TEXT));
        textContent.clear();
    }

(5) The above code is what I'm now using as it's the only way I can find to
do it. Previously I used 'elem.setChildren(elem.getChildren())' which was a
kludge but it worked. I find the prospect of things breaking when I upgrade
my JDOM version a little unsettling but then I suppose we are working with
beta code.

Hope nobody is offended by any of this.

Duncan.

-----Original Message-----
From: Jason Hunter [mailto:jhunter at acm.org]
Sent: 06 December 2002 22:39
To: duncan.loveday at bt.com
Cc: jdom-interest at jdom.org
Subject: Re: [jdom-interest] Problem with 'setChildren' on JDOM B8


> Has anyone come across a problem with 'setChildren()' not clearing textual
> content on JDOM B8 ?

Use setContent() instead.  setContent() clears text content like you
want, and besides, setChildren() is deprecated.

-jh-



More information about the jdom-interest mailing list