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

Patrick McFarlane PMcFarlane at lendx.com
Mon Feb 25 18:23:24 PST 2002


	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



More information about the jdom-interest mailing list