[jdom-interest] XMLOutputter to the rescue (get/setText)

guru at stinky.com guru at stinky.com
Wed Jul 11 17:37:21 PDT 2001

On Wed, Jul 11, 2001 at 05:21:22PM -0400, Elliotte Rusty Harold wrote:
> However, if
>   getText DOES recurse
>  setText replaces the entire content

OK, fine, whatever. I'm just nervous when a method that looks like an
accessor has to visit lots of other objects before it returns, but
I'll get over it.

+0 on getText recursing and concatenating all and only string content
from the target and its contents

+1 on setText replacing the entire content (or -1 on Brett's original

> >However, for the XML-as-document folks, for whom elements can contain mixed text and elements with their own text etc., like
> >
> ><warning>
> > Do <b>not</b> eat the <font color="#FFFF00">yellow</font> snow.
> ></warning>
> >
> >I propose using (recommending to use) XMLOutputter.
> >

>  No, a recommendation is not a solution. We should not provide
> methods that can fail without warning in such a common use case. I
> think there are three acceptable solutions. In order of preference,

I didn't mean changing getText to do that.  I meant putting in the
documentation for getText, "Here's what you'll get. In order to get
different-looking output, use XMLOutputter, for example, blah blah

> 1. We recurse the text so the method always works.


> 2. We throw an exception in the face of mixed content.

-1 since exceptions should not be thrown lightly, and unchecked
exceptions should have a damn good reason for being thrown

> 3. We delete the getText() method completely.


>  The current behavior is simply not an option, even with a Javadoc
> note on the point. It's just way too dangerous.

It's dangerous because...?  I agree it's a little unintuitive, but not
dangerous.  (Not as dangerous as an unchecked exception, for instance,
which could unexpectedly kill a thread without warning.)

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