[jdom-interest] Confused ? I am

Jason Hunter jhunter at collab.net
Fri Mar 30 01:31:48 PST 2001

"Kenworthy, Edward" wrote:
> Be gentle, this is my first post!


> Ah ha! I thought, I have an out of date version. However checking
> www.jdom.org it seems that beta 6 is the latest version and there is no
> release 1.0, despite what Brett (one of the authors of the JDOM spec !) says
> in his book. Confused ? I am !

The book covers an early beta.  There's never actually been a 1.0
release despite what the book says.  The bottom of the jdom.org web page
has a link concerning updates.

> So my questions are:
> 1. How do I change just the text part (eg what is returned by getText() of
> an Element without wiping out the child elements, which setText(), does.

Can't really do it with one method because there's not one text
section.  You actually have *three* text blocks in your example because
of whitespace which by default is preserved, per the XML spec:

        Some text or other.

So the text blocks are 
"\n        Some text or other.\n       "
"\n        "

A getText() can concatenate them and a getTextTrim() and do the same
minus the whitespace, but how can setText() do a simple replace? 
Another example is:

<SomeElement>This <b>bold</b> is a sentence</SomeElement>

Here you can see why the compromise is for setText() to just replace the
whole content.  The Javadocs explain.  I agree it'd be nice if setText()
could better correlate to getText() but I don't see how.

> 2. What's going on with the O'Reilly book. Was Brett beng optimistic when he
> wrote it, expecting the 1.0 version to be available when it was published ?

Yep, he's an optimistic guy.

> 3. What has happened to getContent() and setContent() ?

They're now getText() and setText().

> I'm feeling a bit like I am banging my head against a brick wall so any help
> would be appreciated.

Trust the Javadocs.


More information about the jdom-interest mailing list