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

Alex Rosen arosen at silverstream.com
Tue Jul 10 12:04:50 PDT 2001

> >I propose one thing: if your XML uses (or can use) mixed
> content, you should
> >*NOT* be calling getText() or setText() or whatever we call them.
> If the method won't work we shouldn't provide it. Don't load
> bullets into guns, give them to users, and say "Go ahead,
> pull the trigger, I'm wearing a bullet proof vest." They may
> miss and hit the person next to you who isn't decked out in Kevlar.

Like I said, they're really useful for data-oriented applications, but not for
document-oriented applications. I'd really, really hate to lose them (if you
haven't guessed, I'm using JDOM for data-oriented XML).

> >I think that your proposed change has the same problems. It
> works well for your
> >example, but it will lull users into using getText() for
> mixed content, when I
> >believe they should not. If the XHTML gets more complex,
> then your proposed
> >solution falls apart. For example, in the XHTML
> "<p>ONE</p><p>TWO</p>", the
> >whitespace value of getText() would probably not be what
> you're looking for.
> Can you elaborate? I don't see any problem at all here.
> >What if the XHTML contain a <ul> element or a <table>?
> Asking for the value of a ul returns the complete text
> content of the ul. Asking for the value of a table returns
> the complete text content of the table. Asking for the value
> of a foo returns the complete text content of the foo.

Sorry I wasn't clear - I was talking about calling getText() on the node one
level up. You wanted

  Do <strong>NOT</strong> eat the yellow snow!

to return "Do NOT eat the yellow snow!". (Presumably you "normalize" the text
after retrieving it.) But what if you have:

  Do not eat the
  <ul><li>yellow or</li><li>green</li></ul>

After normalization, you'll get "Do not eat the yellow orgreen snow!". This is
a contrived example, but my point is, there's a lot of stuff going on with
mixed-content XML, and calling getText() presents an incomplete picture, no
matter how it's implemented. I don't think it should be encouraged.


More information about the jdom-interest mailing list