[jdom-interest] setText() to replace children?

Ian Lea ian.lea at blackwell.co.uk
Wed Jul 11 02:52:12 PDT 2001


Bart Read wrote:
> 
> I have to broadly agree with Alex Rosen on this one.  getText() should just
> get the text, possibly throwing a RuntimeException if there is mixed
> content.  If you want all of the content you should use getContent().  I
> think the function that setText() should perform is more open to debate.  My
> personal opinion is that it should replace all child content of the element
> in question.  If you want to set mixed content then there are more
> appropriate methods: setContent(List content) and the various forms of
> addContent().  If you're dealing with mixed content I really can't see why
> you'd want to use getText() in the first place.  Conversely if you have an
> element that only contains text do you really want to get back a List and
> then have to cast the first object to a String in order to get at it?

Absolutely not.  I use getText() and setText() a lot on elements
that I know only contain text and they do exactly what I want. Would
have no objection to an exception being thrown if the element didn't
just contain text.


--
Ian.
ian.lea at blackwell.co.uk



More information about the jdom-interest mailing list