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

Elliotte Rusty Harold elharo at metalab.unc.edu
Tue Jul 10 12:21:37 PDT 2001

At 3:04 PM -0400 7/10/01, Alex Rosen wrote:

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

You misunderstand. Your data-oriented applications work just like they do now. Nothing changes for them. You can still use getText() just like you're using it now. 

 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:

Don't presume. No normalization would be performed. All white space is preserved by default unless the user specifically asks that it be thrown away. 

>  Do not eat the
>  <ul><li>yellow or</li><li>green</li></ul>
>  snow!
>After normalization, you'll get "Do not eat the yellow orgreen snow!". 

OK. Now I see your problem. There's no normalization, but I still maintain that 

  Do not eat the
  yellow orgreen

is to be preferred to "Do not eat the 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.

Perhaps not encouraged, but if we allow it at all it should not throw away information the user doesn't ask to be thrown away. 

| Elliotte Rusty Harold | elharo at metalab.unc.edu | Writer/Programmer |
|          The XML Bible, 2nd Edition (Hungry Minds, 2001)           |
|              http://www.ibiblio.org/xml/books/bible2/              |
|   http://www.amazon.com/exec/obidos/ISBN=0764547607/cafeaulaitA/   |
|  Read Cafe au Lait for Java News:  http://www.cafeaulait.org/      | 
|  Read Cafe con Leche for XML News: http://www.ibiblio.org/xml/     |

More information about the jdom-interest mailing list