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

xmlserializer - serialize float cultureinfo

hello everyone,
I'm using the XmlSerializer to generate Xml-Files of my classes.
I do have some float's and double's that also should get serialized.

At the moment, XmlSerializer generates something like the following for
float numbers:
<myVal>4000.5</myVal>

But i need to get this in german culture... there shoud be a comma instead
of the point, so it should look like:
<myVal>4000,5</myVal>

It's REALLY important, that I can serialize it like that, because the
Xml-file is sent to a interface that only accepts the second number format.

I already tried to add the following before serialization, but it didn't work.

System.Threading.Thread.CurrentThread.CurrentCultu re = new
System.Globalization.CultureInfo("de-AT");
System.Threading.Thread.CurrentThread.CurrentUICul ture =
System.Threading.Thread.CurrentThread.CurrentCultu re;

I don't have to get the best solution, ANY solution would help..

Thanks in advance,
Christian
Jun 15 '07 #1
1 7729
a solution is to implement IXmlSerializable for the class which contains the
float

and WriteXml :

public void WriteXml(XmlWriter writer)
{
CultureInfo culture = new CultureInfo("at-DE");
NumberFormatInfo formatInfo = culture.NumberFormat;
writer.WriteElementString("myVal", System.Convert.ToString(myVal,
formatInfo));
}
Didier
"Christian" <Ch*******@discussions.microsoft.comwrote in message
news:00**********************************@microsof t.com...
hello everyone,
I'm using the XmlSerializer to generate Xml-Files of my classes.
I do have some float's and double's that also should get serialized.

At the moment, XmlSerializer generates something like the following for
float numbers:
<myVal>4000.5</myVal>

But i need to get this in german culture... there shoud be a comma instead
of the point, so it should look like:
<myVal>4000,5</myVal>

It's REALLY important, that I can serialize it like that, because the
Xml-file is sent to a interface that only accepts the second number
format.

I already tried to add the following before serialization, but it didn't
work.

System.Threading.Thread.CurrentThread.CurrentCultu re = new
System.Globalization.CultureInfo("de-AT");
System.Threading.Thread.CurrentThread.CurrentUICul ture =
System.Threading.Thread.CurrentThread.CurrentCultu re;

I don't have to get the best solution, ANY solution would help..

Thanks in advance,
Christian

Jun 15 '07 #2

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

Similar topics

2
by: Chris Aitchison | last post by:
Hello, I am attempting to have a class that I have written serialize so that it can be both passed as a parameter or return value for a webservice, and also be serialized to disk using the...
4
by: Andy Neilson | last post by:
I've run across a strange behaviour with XmlSerializer that I'm unable to explain. I came across this while trying to use XmlSerializer to deserialize from a the details of a SoapException. This...
16
by: Bob Rock | last post by:
Hello, when serializing an array of elements of a class Classname using XmlSerializer.Serialize() I get an XML like the following: <?xml version="1.0"> <ArrayOfClassname> ....... ..........
2
by: magister | last post by:
Hello I got this working but it is not how I really want it, basically I have an xml file which has a root of <test> and can be filled with 3 different types of <question> elements with different...
0
by: keith bannister via .NET 247 | last post by:
(Type your message here) -------------------------------- From: keith bannister Hi, I'm new to .net (as of last week) but here goes. I want to serialize/deserialize a file the conforms...
3
by: Loui Mercieca | last post by:
Hi, I have created a class, named FormField , which basically contains two fields, name and value. I have set the tag before the class and the field is set as an XmlAttribute whil the name as...
8
by: cd~ | last post by:
I can provide a test app, the news server won't allow me to post the files because they are too large (93KB and 1.2KB) I downloaded the ESRI ArcXml schema and generated the classes from the...
2
by: Abra | last post by:
Hello, I am using the XmlSerializer clas to serialize/deserialize XML files. I have a XML file containing elements which have attributes of type float. If the value of the float attribute in my...
0
by: Kristopher Wragg | last post by:
Hi, I'm having a problem with XMLSerializer, I have classes like the following: public abstract class EulerObject { private Rectangle rect; private string guid = "";
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
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...

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.