I've tried xml:space="preserve" and still no luck.
----- Original Message -----
From: "Jörg Schaible" <[EMAIL PROTECTED]>
To: "Jakarta Commons Users List" <[email protected]>
Sent: Friday, January 25, 2008 7:09 AM
Subject: RE: Whitespace in XML configuration file
Sorted conversation ...
Oliver Heger wrote:
Ricardo Espírito Santo schrieb:
Hello,
on
http://commons.apache.org/configuration/changes-report.html you refer
that "Empty elements or elements whose content consists only of
comments or whitespace are now taken into account by
XMLConfiguration. They are added to the configuration; their value
is an empty string. Fixes CONFIGURATION-6
<http://issues.apache.org/jira/browse/CONFIGURATION-6>. "
But this introduced another problem, when a configuration string is
really meant to be whitespace then we have no way of retrieving that
value...
so <key> </key>
maps to java as key="";
"
at first I would like to ask you to send such questions to
the commons
user mailing list [1]. They are probably of interest for other users,
too, and the audience that can answer your question is much bigger.
To your problem: I don't think that you have much control
over the white
space processing the XML parser does. You can never be sure whether a
space in the file is intended as value of a property or
exists only for
cosmetic reasons. Take for instance a document fragment like
the following:
<key>
<sub>test</sub>
</key>
In this case key will have some text content consisting only of white
space. Should it be used or not?
What you can do is using attributes. The values of attributes
should be
preserved without changes. So you could try something like this:
<key value=" "/>
No! Especially attributes are normalized according the XML spec by every XML
parser: http://www.w3.org/TR/REC-xml/#AVNormalize. They *have to*.
Now as an answer to his reply I decided to follow his advice
as this may in fact be of some interest to other users and
post it here:
I have tried the parameter option with <key value=" " /> but
had no luck as this was also parsed to "".
No wonder! Otherwise you parser would have been broken ;-)
I have a workaround but which defies half of the purpose of
this lib. If one should provide a second parameter to
getString() a default value is taken into consideration which
one could set to be " " a space.
so getString("value", " "); and then on the actual XML file
we should ommit the value, so: <key />.
If you try to keep whitespaces for values you have to use the tag values:
http://www.w3.org/TR/REC-xml/#sec-white-space. This is what
commons-configurations must support.
- Jörg
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]