[jdom-interest] Request for new methods removeText(), replaceText(), & replaceContent().
Steven D. Keens
skeens at planetfred.com
Wed Mar 21 07:34:03 PST 2001
>Subject: Re: [jdom-interest] Request for new methods removeText(),
>replaceText(), & replaceContent().
>> I have attached a version of Element.java with three new methods:
>> public boolean removeText();
I understand that you do not want to bloat the API -- I agree, but I
subscribe to the theory of having a minimal but complete API. When it
comes to Element, I don't believe it is complete because we can
remove every type of content except text content. I have to jump through
hoops to do it. If I want to remove text from my Element then I have
to get the mixed content, iterate over all the objects keeping track
of the one's that I care about, and finally set the mixed content.
For that reason I think something that allows us to remove text from
an Element is useful. Maybe a removeContent( String ) and
removeContent( CDATA ) would satisfy your vision of the API.
>Your impl iterates through the mixed content and removes all String and
>CDATA entries. I'm not sure that's generally useful.
>> public void replaceText( String newText );
>This does the above but then adds at the end the new text. It's not
>really a replacement then, because a<?pi?>b becomes <?pi?>newText.
>For both of these, I think it better to use the List API to make
I thought you might have a problem with this one. It's one I need
but I can keep it in my own utilities.
>> public void replaceContent( Element oldElement, Element
>This one there may be a use for. List doesn't have a replace() method.
>Too bad. But you can simulate it easily enough, so I'm not sure it's
>worth the API bloat.
This is one that I really thought would make it. As you say,
simulating is easy enough, as I have shown, with my implementation.
But I just realized that I forgot to update/maintain the
parentage (lineage?) for both the new and old elements which needs
to be done otherwise you may get an IllegalAddException. Also, generally
speaking, the usual set of methods on a container are add(), remove(),
and replace() or set().
Steven Keens mailto:skeens at planetfred.com
PlanetFred Inc. http://www.planetfred.com
44 Byward Market, Suite 240, Ottawa, ON, K1N 7A2, Canada
More information about the jdom-interest