commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Kitching <>
Subject Re: [Digester] troubles with xml:space="preserve"
Date Wed, 01 Nov 2006 10:57:44 GMT
On Tue, 2006-10-31 at 22:35 +0200, Sharon Dagan wrote:
> Hi,
> Digester 1.7 doesn't seem to honor xml:space="preserve".
> And so:
> <text xml:space="preserve">Hello{NEWLINE}</text>
> Where {NEWLINE} is '\n'.
> Digester reports that text=Hello, omitting the new line character ('\n').
> Any idea how to fix this?

I'm not particularly familiar with the xml:space attribute, but a google
search found this page that describes it reasonably well:

I believe the Digester class itself gathers the text content of an
element without stripping any space.

However the CallMethodRule does this:
    public void body(String bodyText) throws Exception {
        if (paramCount == 0) {
            this.bodyText = bodyText.trim();

and CallParamRule does this:

    public void body(String bodyText) throws Exception {
        if (attributeName == null && !fromStack) {
            // We must wait to set the parameter until end
            // so that we can make sure that the right set of parameters
            // is at the top of the stack
            if (bodyTextStack == null) {
                bodyTextStack = new ArrayStack();


I presume this is causing what you are seeing. 

There is currently no option on CallMethodRule or CallParamRule class to
disable this text trimming functionality. This default behaviour is
generally what is wanted so that
are treated the same.

However I agree it would be nice to have the ability to preserve
whitespace as an option (though not the default). 

As I understand it, the xml:space attribute is simply part of the
element attributes as normal. Therefore the CallMethod/CallParam rules
could check for it in their begin methods and set a flag to determine
whether to trim text or not. If you would like to submit a patch
(including unit tests) to implement support for preserving whitespace
then I would be happy to commit it (assuming no objections from anyone
else). Before doing too much work on that, though, I would recommend
posting an outline of your intended implementation for feedback.

Alternatively, you could create your own variants of these rules, ie
copy the existing CallMethodRule/CallParamRule source code, change the
apache package name to your package name, and change the behaviour to
what you need. Then just configure your Digester instance using
instances of your rule classes rather than the default ones.



To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message