473,396 Members | 1,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Regional settings in XML ?

ORC
How is the best way (the standard way) to handle changes in regional
settings in XML?
If a XML file is generated with the dot as the decimal symbol (like in US)
and a user changes to use a comma as the decimal symbol (like in franche).
Let me give an example: An application saves a number value defined as
double in a node. The value will be converted to a string as e.g. 3.1415
(regional settings = US). A user changes the regional settings to 'Franche'
and when the application reads the value it will return an error because it
doesn't understand the dot sign.

Thanks,
Ole
Nov 16 '05 #1
8 2195
ORC <or*@sol.dk> wrote:
How is the best way (the standard way) to handle changes in regional
settings in XML?
If a XML file is generated with the dot as the decimal symbol (like in US)
and a user changes to use a comma as the decimal symbol (like in franche).
Let me give an example: An application saves a number value defined as
double in a node. The value will be converted to a string as e.g. 3.1415
(regional settings = US). A user changes the regional settings to 'Franche'
and when the application reads the value it will return an error because it
doesn't understand the dot sign.


The best thing to do, IMO, is store them in the invariant culture -
separate the XML form from the form the user will see.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
ORC
Thanks. Do you have a simple example of how to save and load a variable in
invariant format - I have been looking for things like that, but I can't
find a solution.

Thanks
Ole

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
ORC <or*@sol.dk> wrote:
How is the best way (the standard way) to handle changes in regional
settings in XML?
If a XML file is generated with the dot as the decimal symbol (like in US) and a user changes to use a comma as the decimal symbol (like in franche). Let me give an example: An application saves a number value defined as
double in a node. The value will be converted to a string as e.g. 3.1415
(regional settings = US). A user changes the regional settings to 'Franche' and when the application reads the value it will return an error because it doesn't understand the dot sign.


The best thing to do, IMO, is store them in the invariant culture -
separate the XML form from the form the user will see.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #3
ORC <or*@sol.dk> wrote:
Thanks. Do you have a simple example of how to save and load a
variable in invariant format - I have been looking for things like
that, but I can't find a solution.


If you use the XmlConvert class, it already does things in an invariant
format. If you're using another way of saving and loading, you'll need
to explain how you're doing it so we can see whether there's a way you
can do it in a culture neutral way.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4
ORC
Hi,

When writing a value to the XML I use: MyUnknownTypeValue.ToString();
When reading from the XML I use:
MyUnknownTypeValue =
Convert.ChangeType(LoadedValue, TypeOf(MyUnknownTypeValue), null );

Thanks,
Ole

When saving I simply use
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
ORC <or*@sol.dk> wrote:
Thanks. Do you have a simple example of how to save and load a
variable in invariant format - I have been looking for things like
that, but I can't find a solution.


If you use the XmlConvert class, it already does things in an invariant
format. If you're using another way of saving and loading, you'll need
to explain how you're doing it so we can see whether there's a way you
can do it in a culture neutral way.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #5
ORC <or*@sol.dk> wrote:
When writing a value to the XML I use: MyUnknownTypeValue.ToString();
When reading from the XML I use:
MyUnknownTypeValue =
Convert.ChangeType(LoadedValue, TypeOf(MyUnknownTypeValue), null );


Right. I suggest you use the XmlConvert class instead of that then, to
give you more control.

(You *could* temporarily change the culture of the current thread, but
I think that's a bit of a grotty hack way of doing it.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #6
ORC
The XmlConvert doesn't unfortunately accept an object as a parameter e.g.
like this:
"XmlConvert(field.GetValue(MyClass));"
But:
"field.GetValue(MyClass).ToString();"
works!

the field is derived in a foreach fieldInfo loop.

So the temporarily change to a US culture would probably be the only
solution left, or am I missing something? But how do I change the culture of
the current thread?

Thanks
Ole
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
ORC <or*@sol.dk> wrote:
When writing a value to the XML I use: MyUnknownTypeValue.ToString();
When reading from the XML I use:
MyUnknownTypeValue =
Convert.ChangeType(LoadedValue, TypeOf(MyUnknownTypeValue), null );


Right. I suggest you use the XmlConvert class instead of that then, to
give you more control.

(You *could* temporarily change the culture of the current thread, but
I think that's a bit of a grotty hack way of doing it.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #7
ORC <or*@sol.dk> wrote:
The XmlConvert doesn't unfortunately accept an object as a parameter e.g.
like this:
"XmlConvert(field.GetValue(MyClass));"
But:
"field.GetValue(MyClass).ToString();"
works!
Well yes, you'll need to do a bit more work - it's not a one line
change. You need to call the appropriate overload of
XmlConvert.ToString when going to XML, and
XmlConvert.ToByte/Boolean/etc on the way back.
the field is derived in a foreach fieldInfo loop. So the temporarily change to a US culture would probably be the only
solution left, or am I missing something? But how do I change the culture of
the current thread?


I really don't recommend it, but you can use
Thread.CurrentThread.CurrentCulture = ...;

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #8
ORC
I found a great workaound that works very well - the best part is that it
can be done in ONE line and that is 'Clean' code:

string elementString = Convert.ToString(Convert.ChangeType(fieldValue,
typeof(string), System.Globalization.CultureInfo.InvariantCulture) );

Ole

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
ORC <or*@sol.dk> wrote:
The XmlConvert doesn't unfortunately accept an object as a parameter e.g. like this:
"XmlConvert(field.GetValue(MyClass));"
But:
"field.GetValue(MyClass).ToString();"
works!


Well yes, you'll need to do a bit more work - it's not a one line
change. You need to call the appropriate overload of
XmlConvert.ToString when going to XML, and
XmlConvert.ToByte/Boolean/etc on the way back.
the field is derived in a foreach fieldInfo loop.

So the temporarily change to a US culture would probably be the only
solution left, or am I missing something? But how do I change the culture of the current thread?


I really don't recommend it, but you can use
Thread.CurrentThread.CurrentCulture = ...;

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Grumfish | last post by:
Is there a way to tell Java what localization to use so applications and the compiler doesn't default to the system's setting? I'm using a computer with Windows 2000 with a regional setting of...
1
by: nerman | last post by:
Hello I have a problem with the regional settings. I have set the regional settings of the web server to display the numbers in this format 123.456,78 But when I open my web site all number are...
4
by: Jonathan | last post by:
Dear All, I am trying to set a webserver to use French regional settings for testing ASP pages. According to http://support.microsoft.com/kb/q306044, for IIS5, this is a matter of changing...
2
by: Bob Dydd | last post by:
Hi Everbody Question Changing the regional settings ie. from UK to US AUS etc, Access retains the original currency format that the application was created in. So if an mdb that is written...
3
by: Emmanuel | last post by:
I want to know the decimal separator and the group separator character that the user has set in Regional Settings in Control Panel. I tryied to use...
1
by: John | last post by:
Hi, The following behavior when using J# vs. C# is really bothering me. When I have the regional settings on my workstation set to a non-US settings (eg: Danish); it seems that J# disregards...
12
by: magister | last post by:
Hello, I know I can set the Culture to what I want, but shouldn't the current culture be taken from the regional settings on the web server's control panel!!! Mine is set to "united kingdom"...
7
by: Fred Flintstone | last post by:
I'm writing a VB.Net windows forms application. This line of code: Personal.EffectiveDate = GridRow2.Cells("New Value").Value.ToString.Trim Fails with this error: Cast from string...
16
by: Colmag | last post by:
I've written an application with vb.net 2003 (framework 1.1) which automates a 3rd party viewing/printing application (via an activex control). I've released several versions over the last year...
1
by: Luis Lanuza | last post by:
Hi all, I can't get Visual Studio 2003 to recognize my WindowsXP SP2 regional settings. For ex: On Control Panel / Regional Settings / Regional Options Tab, my standadrs and formats corresponds...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.