You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Ricardo Espírito Santo <ri...@gmail.com> on 2008/01/25 00:01:11 UTC

Whitespace in XML configuration file

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

Re: Whitespace in XML configuration file

Posted by Oliver Heger <ol...@oliver-heger.de>.
Jörg Schaible schrieb:
> Hi Oliver,
> 
> Oliver Heger wrote:
>> Ricardo Espírito Santo schrieb:
>>> I've tried xml:space="preserve" and still no luck.
>>>
>> Yes, this special attribute is not yet supported. If you
>> like, you can
>> open a new ticket in our bug tracking system [1] and enter an
>> enhancement request. 
>>
>> @Jörg: Would you be interested in providing a patch?
> 
> intestested, yes. Realistically currently no. Within the next two months I will have to refurbish our new home and move over. Real world beats virtual ;-)
> 
> - Jörg
> 
I have created a Jira ticket for this issue [1], so it won't get lost.

Oliver

[1] https://issues.apache.org/jira/browse/CONFIGURATION-307


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


RE: Whitespace in XML configuration file

Posted by Jörg Schaible <Jo...@Elsag-Solutions.com>.
Hi Oliver,

Oliver Heger wrote:
> Ricardo Espírito Santo schrieb:
>> I've tried xml:space="preserve" and still no luck.
>> 
> 
> Yes, this special attribute is not yet supported. If you
> like, you can
> open a new ticket in our bug tracking system [1] and enter an
> enhancement request. 
> 
> @Jörg: Would you be interested in providing a patch?

intestested, yes. Realistically currently no. Within the next two months I will have to refurbish our new home and move over. Real world beats virtual ;-)

- Jörg

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: Whitespace in XML configuration file

Posted by Oliver Heger <ol...@oliver-heger.de>.
Ricardo Espírito Santo schrieb:
> I've tried xml:space="preserve" and still no luck.
> 

Yes, this special attribute is not yet supported. If you like, you can 
open a new ticket in our bug tracking system [1] and enter an 
enhancement request.

@Jörg: Would you be interested in providing a patch?

Thanks
Oliver

[1] http://commons.apache.org/configuration/issue-tracking.html

> ----- Original Message ----- From: "Jörg Schaible" 
> <Jo...@Elsag-Solutions.com>
> To: "Jakarta Commons Users List" <us...@commons.apache.org>
> 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: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: Whitespace in XML configuration file

Posted by Ricardo Espírito Santo <ri...@gmail.com>.
I've tried xml:space="preserve" and still no luck.

----- Original Message ----- 
From: "Jörg Schaible" <Jo...@Elsag-Solutions.com>
To: "Jakarta Commons Users List" <us...@commons.apache.org>
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: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


RE: Whitespace in XML configuration file

Posted by Jörg Schaible <Jo...@Elsag-Solutions.com>.
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: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org