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

Jason Hunter jhunter at acm.org
Mon Feb 25 18:53:44 PST 2002


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?

-jh-

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, etc.)
> from an element without passing an Object argument would be very useful.
> This would be roughly analogous to the Element removeChildren(). The inverse
> 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:
> http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com



More information about the jdom-interest mailing list