[jdom-interest] setText() to replace children?
arosen at silverstream.com
Tue Jul 10 10:12:11 PDT 2001
Argh! Once again, the conflict between data-oriented and document-oriented XML
rears its head.
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. Using mixed
content is complex, and I think that trying to make these methods work better
for mixed content will only end up making them worse. For the non-mixed content
case, the get/setText() and get/setChildren() methods are really convenient,
but in the mixed content case they just sweep too much important information
under the rug.
> 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 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.
What if the XHTML contain a <ul> element or a <table>? Are we leading people
down the wrong path if we make it work for the simple cases but not for the
more complicated ones? I think we should keep things as-is.
More information about the jdom-interest