469,282 Members | 2,000 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

XMLWriter and NumberDecimalSeparator

Hello, All!

Is it possible to change parameters of locale for writing XML file
(with XMLTextWriter)?

I want DataSet.WriteXML() to use NumberDecimalSeparator "." instead of ","

Regards, Vyacheslav
Nov 12 '05 #1
3 6272


Vyacheslav Lanovets wrote:

I want DataSet.WriteXML() to use NumberDecimalSeparator "." instead of ","


I don't think the result of WriteXml depends on the locale (or culture
as .NET calls it), for instance the output in the following example is
always the same, even if the culture is changed:

DataSet dataSet = new DataSet("DoubleTest");
DataTable dataTable = new DataTable();
dataTable.Columns.Add(new DataColumn("double", typeof(double)));
DataRow dataRow = dataTable.NewRow();
dataRow["double"] = 2.5;
dataTable.Rows.Add(dataRow);
dataSet.Tables.Add(dataTable);
dataSet.WriteXml(Console.Out);
Console.WriteLine();

string[] cultures = new string[] { "en-US", "en-GB", "de-DE", "de-CH"};
foreach (string cultureName in cultures) {
Thread.CurrentThread.CurrentCulture = new CultureInfo(cultureName);
Console.WriteLine("Culture is {0}. XML is: ",
Thread.CurrentThread.CurrentCulture);
dataSet.WriteXml(Console.Out);
Console.WriteLine();
}

The decimal separator there is always '.' as it should be for double data.

Perhaps I misunderstand what you try to do, please explain in more
detail if you still have problems.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Nov 12 '05 #2
"Vyacheslav Lanovets" <xentrax_umail_ru> wrote in message news:%2****************@TK2MSFTNGP12.phx.gbl...
Is it possible to change parameters of locale for writing XML file
(with XMLTextWriter)?
XmlTextWriter produces data representations that are formatted
using the invariant culture.

The XML Schema Datatypes W3C recommendation, which an
ADO.NET DataSet depends on to represent strongly-typed data
in XML, specifies in Section 3.2.3.1 that the lexical representation
of a decimal datatype must use the period as it's decimal separator.

http://www.w3.org/TR/xmlschema-2/#decimal

Section 3.2.5.1 indicates that the lexical representation of a double
datatype must represent it's mantissa and exponent as decimals,

http://www.w3.org/TR/xmlschema-2/#double

The lexical representations for these datatypes are consistent with
ISO 11404 which covers how numeric data (for instance) should
be represented to prevent ambiguities introduced by the data when
it is going to be consumed within different cultural contexts.
I want DataSet.WriteXML() to use NumberDecimalSeparator "."
instead of ","


Here is why that's a bad idea. Suppose you're serializing a decimal
value of 2.501 into XML using a different decimal separator. If
you serialize in a culture where the decimal separator is "," and the
thousands separator is "." then this lexical representation actually
represents the number two thousand five hundred one.

However, when that value gets read later in a culture where the
decimal separator is "." and the thousands separator is "," it gets
interpretted as two and five hundred one thousandths.

I hope that code isn't responsible for air traffic control. :-)

Heathrow - Charlie 9-9-9 we're turning you over to Laguardia
air traffic control. You're showing an altitude of 2,501 meters.
Over.

Laguardia - Flight Charlie 9-9-9, this is Laguardia flight tower in
New York. We see that your altitude is 2 1/2 feet. Is something
wrong? Over.

If you're going to be displaying this to the end user (as opposed to
performing further processing on it as a double or decimal datatype)
then this formatted lexical representation should be typed as a string.

That is, you should make the column a string and format it before
serializing to XML.
Derek Harmon
Nov 12 '05 #3
Hello, Martin!
You wrote on Mon, 21 Feb 2005 17:45:54 +0100:

MH> I don't think the result of WriteXml depends on the locale (or culture
MH> as .NET calls it), for instance the output in the following example is
MH> always the same, even if the culture is changed:

Sorry, I made a mistake and the problem was in my code:

object[] ins_row = ....;
cnv_ds.Tables[0].Rows.Add(ins_row);

Rows.Add() performs automatic conversion from "double" to "String" because
DataType of the column is String instead of double. And by default
the conversion uses current Culture.

Regards, Vyacheslav
Nov 12 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Vyacheslav Lanovets | last post: by
3 posts views Thread by Michael Malinak | last post: by
1 post views Thread by jschell | last post: by
2 posts views Thread by Harry | last post: by
1 post views Thread by MAF | last post: by
9 posts views Thread by =?Utf-8?B?UGF1bA==?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.