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

Alex Chaffee guru at stinky.com
Wed Jul 11 11:34:22 PDT 2001

Steven D. Keens wrote:

> I like your idea but wouldn't it be better if the exception is thrown when
> there is mixed content.  Also, getText() could react the same way, by
> throwing an exception if it contains mixed content.  Thus, we retain the
> convenience of the two methods (isn't that why they exist, for convenience).
> Plus we have a consistent and symetric API that behaves predictably.

No exceptions!  Exceptions are bad!  I don't want to have to catch an 
exception every time I call getText, and I also don't want my thread to die 
with an unchecked exception if the program reads a data file with invalid 
mixed content.  getText should not throw an exception; it should return a 
String like it says it does.  I don't even really care what that string 
contains as long as it's unambiguous and documented.

(Though I like Rusty's "recurse" proposal the more I think about it.)

If anyone wants more complex behavior (wrt whitespace or whatever) they can 
walk the list themselves in 3 lines of code, or just use XMLOutputter.

Alex Chaffee                       mailto:alex at jguru.com
jGuru - Java News and FAQs         http://www.jguru.com/alex/
Creator of Gamelan                 http://www.gamelan.com/
Founder of Purple Technology       http://www.purpletech.com/
Curator of Stinky Art Collective   http://www.stinky.com/

More information about the jdom-interest mailing list