[jdom-interest] Element.getContentTrim() ?

Alexander Hvostov root at aoi.dyndns.org
Mon Oct 8 10:26:19 PDT 2001

On Mon, 8 Oct 2001 12:40:08 -0400, "Alex Rosen" <arosen at silverstream.com> wrote:

> > That's NOT what I was asking for. I was asking for, quite
> > simply, all text
> > content _directly_ contained in an Element to get trimmed.
> > This does not mean recursing into its child Elements.
> Sorry, I thought I understood but I guess I don't. Can you give an example
> of what your proposed method would return, and why it's needed?
> Thanks,
> Alex

A java.util.List, just like the one returned by getContent(), but with String
elements trimmed as with getTextTrim().

This is needed so that indentation, newlines, and other such whitespace gets
trimmed off, so that markup like:

    There is
    </b> here!

gets trimmed to:

  <p>There is some <b>text
    </b> here!</p>

Or, to represent the Lists:

    java.lang.String "\n    There is\n     some\n    "
    org.jdom.Element "<b>text\n    </b>"
    java.lang.String " here!\n  "

gets trimmed to:

    java.lang.String "There is some "
    org.jdom.Element "<b>text\n    </b>"
    java.lang.String " here!"

Note that trimming here is NOT done recursively; that's the application's job.
Thus, the newline and indentation at the end of the <b> element's text content

In the example of HTML type markup, this is useful because it allows for having
mixed content (as I demonstrate here) in the input markup, but having it look
right (ie, with newlines, indentation, etc trimmed off) when rendered on the
user's display.

This is also necessary for a program I've written that uses XML as input and
does something conceptually similar -- takes XML input and renders formatted
output -- and therefore needs this sort of auto-trim for the same reason -- so
that newlines and indentation and such don't appear in the output, as with



More information about the jdom-interest mailing list