[jdom-interest] API enhancement request: Element.removeConten t()

Patrick McFarlane PMcFarlane at lendx.com
Tue Feb 26 13:03:31 PST 2002

Again maybe I'm missing something, but when I use the setContent(null)
method or getContent().clear() my content still has parent relationships so
that I get an error messages like the following:

org.jdom.IllegalAddException: The comment " Display Element Definitions "
could not be added as content to "localizableDisplay": The comment already
has an existing parent "localizableDisplay"

If I use the Element removeChildren() method, that sets the parent
relationship to null which lets me avoid the problem above. I'm wondering if
a removeContent method could also free the parent relationships of what was

I'm sure that I can work around this by iterating through my list of content
and doing the equivalent of a detach() for each, but I just thought this
might be a useful method to add.


-----Original Message-----
From: Jason Hunter [mailto:jhunter at acm.org]
Sent: Monday, February 25, 2002 6:54 PM
To: Patrick McFarlane
Cc: 'jdom-interest at jdom.org'
Subject: Re: [jdom-interest] API enhancement request:

Well, with the present API you can setContent(null) or
getContent().clear().  Do we need another method beyond that?

In your usage would it not suffice to say
parentElem.setContent(updatedList) and skip the removeContent() step?


Patrick McFarlane wrote:
>         Not sure if this is in the works or intentionally left out or if
> I've missed something, but, it seems that Element removeContent(), which
> removes all of the various types of content (CDATA, Comment, Element,
> from an element without passing an Object argument would be very useful.
> This would be roughly analogous to the Element removeChildren(). The
> Element setContent(List) is available and it seems odd that Element
> removeContent() is not. My usage is replacing an existing bit of content
> with a revised copy of the content via Jaxen/XPath, keeping the order
> intact. I would like to do the following:
>                 Element oldElem = findElementUsingXPath(elementPath);
>                 Element parentElem = oldElem.getParent();
>                 List siblings = parentElem.getContent();
>                 // find the location of the element to update
>                 int location = findEqualElement(siblings, oldElem);
>                 // create a new List with the new element added Before the
> addBefore element
>                 List updatedList =
> replaceElementInList(siblings,location,newElem);
>                 // remove existing chilren
>                 parentElem.removeContent();  // This method does not
> currently exist
>                 // add new list of children to parent
>                 parentElem.setContent(updatedList);
> Thanks in advance,
>         patrick
> _______________________________________________
> To control your jdom-interest membership:

More information about the jdom-interest mailing list