473,385 Members | 1,757 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,385 software developers and data experts.

XML Serialization and Internationalization

Hi all,

I am serialiizing a c# object to an XML file to save some application
settings. The idea is to ship this xml file along with the application
and deserialize after the application is installalled to use it as a
default settings file. Works fine on machines having the same culture
(en-US) settings. But goes wrong when the object is serialized on a
machine with the culture set to english and and deserialized on
another machine with another culture (it-IT Italy). For this case I
can see that the problem is that in Italy the decimal seperator is a
comma (,) instead of a dot(.) so deserializing ints and doubles
creates a mess.

So my question is, what is the correct way of handling xml
serialization and globalization?

Any help is most appreciated.

Nishant

Jun 27 '08 #1
2 3182
How are you doing the serialization? My understanding is that
XmlSerializer will use invariant formatting for common types...

Are you doing any of the serialization yourself? Perhaps via
IXmlSerializable?

Marc
Jun 27 '08 #2
Could you please give an example of your xml? I tried it out with an
xsd, an xml and a class.
The result showed me that integers were stored without formatting
(which was expected).

Joachim

This is what it looks like:
____________________
XSD:
____________________

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="TestClass" targetNamespace="http://tempuri.org/
TestClass.xsd" elementFormDefault="qualified" xmlns="http://
tempuri.org/TestClass.xsd" xmlns:mstns="http://tempuri.org/
TestClass.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="TestClass">
<xs:complexType>
<xs:sequence>
<xs:element name="Amount" type="xs:int">
</xs:element>
<xs:element name="Language" type="xs:language" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

____________________
class:
____________________

using System.Xml.Serialization;

//
// This source code was auto-generated by xsd, Version=2.0.50727.42.
//
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xs d",
"2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("c ode")]
[System.Xml.Serialization.XmlTypeAttribute(Anonymou sType=true,
Namespace="http://tempuri.org/TestClass.xsd")]
[System.Xml.Serialization.XmlRootAttribute(Namespac e="http://
tempuri.org/TestClass.xsd", IsNullable=false)]
public partial class TestClass {

private int amountField;

private string languageField;

/// <remarks/>
public int Amount {
get {
return this.amountField;
}
set {
this.amountField = value;
}
}

/// <remarks/>

[System.Xml.Serialization.XmlElementAttribute(DataT ype="language")]
public string Language {
get {
return this.languageField;
}
set {
this.languageField = value;
}
}
}

____________________
Unit test:
____________________

[Test]
public void SerializationLocalozation()
{
TestClass tc = new TestClass();
tc.Amount = 1000;
StreamWriter writerEnUS = new
StreamWriter("SerializationTest_en_US.xml");
StreamWriter writerNlNL = new
StreamWriter("SerializationTest_nl_NL.xml");
Thread.CurrentThread.CurrentCulture =
CultureInfo.GetCultureInfo("en-US");
tc.Language =
Thread.CurrentThread.CurrentCulture.ToString();
XmlSerializer xmls = new XmlSerializer(typeof(TestClass));
xmls.Serialize(writerEnUS, tc);
writerEnUS.Close();
Thread.CurrentThread.CurrentCulture =
CultureInfo.GetCultureInfo("nl-NL");
tc.Language =
Thread.CurrentThread.CurrentCulture.ToString();
xmls.Serialize(writerNlNL, tc);
writerNlNL.Close();
}

____________________
Resulting xml en-US:
____________________

<?xml version="1.0" encoding="utf-8"?>
<TestClass xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/
TestClass.xsd">
<Amount>1000</Amount>
<Language>en-US</Language>
</TestClass>

____________________
Resulting xml nl-NL:
____________________

<?xml version="1.0" encoding="utf-8"?>
<TestClass xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/
TestClass.xsd">
<Amount>1000</Amount>
<Language>nl-NL</Language>
</TestClass>
Jun 27 '08 #3

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

Similar topics

9
by: Brian Kelley | last post by:
I have been using gettext and various utilities to provide internationalization for a wxPython application and have not really been liking the process. Essentially it uses a macro-style notation...
19
by: Johannes Nix | last post by:
Hello, yesterday I met a cute person (after my dance class) who told me about an interesting experiment regarding cognition. People were told to read a typed text; However, in every word in the...
6
by: Zlatko Matić | last post by:
What is the easiest way to accomplish internationalization in Access application?
2
by: Internationalization | last post by:
COMSYS Globalization Practice is looking for a C#/.NET Internationalization consultant in OR. Can you please contact me if you are interested or else know someone who would be interested. It will...
3
by: Jules | last post by:
i'm working with translators that just want to translate "web pages" and not deal with resource files. i'd like to have a file structure that looks sort of like this: / <- root directory where...
3
by: Pieter | last post by:
Hi, What's the commonly used way to do internationalization of the text in MessageBoxes? Thanks a lot in advance, Pieter
2
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - Internationalization and Multinationalization in javascript....
1
by: kikisan | last post by:
I am developing a windows service which utilizes the following classes: interface IPersistable; abstract class PersistableObject : IPersistable;
2
by: mkvenkit.vc | last post by:
Hello, I hope this is the right place to post a question on Boost. If not, please let me know where I can post this message and I will do so. I am having a strange problem with std::string as...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...

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.