commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ricardo Espírito Santo <ricardoespsa...@gmail.com>
Subject Whitespace in XML configuration file
Date Thu, 24 Jan 2008 23:01:11 GMT
Regarding the subject I will post here a previous conversation I had with Oliver Heger:

"Hello,

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=" "/>

HTH
Oliver

[1] http://commons.apache.org/configuration/mail-lists.html

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="";
>  
>"

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 "". 

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 />.

Thank you in advance,
Ricardo
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message