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

graste at gmx.de graste at gmx.de
Wed Jul 11 05:23:16 PDT 2001

Hi all - 
I would see setText() and getText() as convenience methods for setting and
getting the content of a XML-'leaf'. If the API-docs are clear at this point
there should be no problems with this at all. Whether it is neccessary to
throw an Exception if there's any other content than only text or not I can't
really decide. It all has their pros and cons. But I would prefer not to throw
an Exception. But that's a personal favor at this time (and the actual project
I'm working on).
But with my (very small) experience with XML data structures I see no *big*
problem with setText() and getText() when they do exactly what they sound
like. Namely setting and getting the content of an Element to some String. For
me it is a often used behaviour. I'm somewhat developing on a project for
medical documentation - and our data structures have no mixed content at all. And
for creating (X)HTML files we use XSLT.
And when I want to use mixed content then it should be no problem for me to
control the behaviour of setting and getting the content out of some
(mixed-content) Elements with methods already in the API now (getContent...).
I don't think that JDom has to cover all the stuff for doing things in that
environment automaticly - that would be no lightweight API in my eyes. And it
would be somewhat complicated (only thinking of the ordering of
mixed-content nodes in different use cases) to implement, isn't it!?

So, as a summary (?) I would prefer the following:

- setText() - sets the content of an Element to a String (and replaces all
former content)
- getText() - retrieves all the text-content of an Element, but not of any
sub-elmts (One should know, that there could be mixed-content in an Element,
and if so one should handle it with care and doesn't use getText)
- setContent(Text, Element, PI, ...) isn't neccessary for me because
probably mostly often used would be setContent(someText).

But other opinions may (co-) exist ;-)


Steffen Gransow

GMX - Die Kommunikationsplattform im Internet.

GMX Tipp:

Machen Sie Ihr Hobby zu Geld bei unserem Partner 1&1!

More information about the jdom-interest mailing list