[jdom-interest] Request for new methods removeText(), replaceText(), & replaceContent().

Jason Hunter jhunter at collab.net
Wed Mar 21 09:36:01 PST 2001

> 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.

Yes, those methods seem appropriate.  I believe the reason they haven't
been implemented is that you might have:

Element root = new Element("root");
root.addProcessingInstruction(new ProcessingInstruction("pi"));

Now how do you remove the second "a"?  A root.removeContent("a") will
remove the first one.  CDATA is similar.

> >>         public void replaceContent( Element oldElement, Element
> >newElement );
> >
> >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().

If we had a replaceContent() for elements would we also need it for the
other types?  Is this worth that many extra methods?


More information about the jdom-interest mailing list