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

Alex Chaffee guru at stinky.com
Wed Jul 11 11:29:23 PDT 2001

I don't know who first said:

>>For example, consider this XHTML element:
>>  Do <strong>NOT</strong> eat the yellow snow!
>>Currently invoking getText() on the p element would produce
>>the string "Do eat  the yellow snow!" This is very
>>unexpected. Worse yet, it might not be noticed at first
>>glance. It is a hidden bug that could produce potentially
>>catastrophic results.

I think whatever we use for getText, the documentation should mention that 
to get a textual representation of the content *including* tags and 
attributes (of children, not of the parent element), you can call

  new XMLOutputter().outputElementContent(element, out)

which is probably what people using XHTML or other mixed content would want 
from a getText anyway.

This allows things like

  A <b>very</b> nice dog.

without corrupting the definition of getText.

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