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

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 6860


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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Vyacheslav Lanovets | last post by:
Hello, All! Is it possible to change parameters of locale for writing XML file (with XMLTextWriter)? I want to change NumberDecimalSeparator from "," to "." Regards, Vyacheslav
3
by: Michael Malinak | last post by:
Since XmlWriter offers so many nice options for formatting, I thought it would be nice to read in via XmlReader, and write back out via XmlWriter. It might be overkill, but I'd also like to be able...
1
by: Marco | last post by:
Hi all, in my system NumberDecimalSeparator is set to ',' so why doing: double toDo = double.Parse(dr.ToString())); toDo is something like 123.0 ?!?!?! Thanks in advance :-)
1
by: jschell | last post by:
The following two cases behave differently in Net 2.0. The Case_Create_StringWriter throws an exception while the Case_XmlTextWriter does not. Is there a problem with this code? Or is this a...
2
by: arne.wiklund | last post by:
Is there an error in the currentCulture.NumberFormat.NumberDecimalSeparator? Take a look at this code: Thread.CurrentThread.CurrentCulture = new CultureInfo("nb-NO");...
2
by: Harry | last post by:
Hi, I am using XMLWriter to build xml and I need to build the element below. How do I do this? <Password format="encrypted">password</Password> Thanks
0
by: Janusz Nykiel | last post by:
I've stumbled upon unexpected behavior of the .NET 2.0 System.Xml.XmlWriter class when using it to write data to a binary stream (System.IO.Stream). If the amount of data is less than a certain...
1
by: MAF | last post by:
Is there a simple way to get the text, xml, from an xmlwriter. I have a XML writer that writes to a file, and I want another function to return the text that the xml writer is produced. Any...
2
by: darrel | last post by:
I want to make my XML as such: <parentItem> <childItem attribute="myAttribute">myContent</childItem> </parentItem> I thought I could just do this: ...
9
by: =?Utf-8?B?UGF1bA==?= | last post by:
Hi I have a .net application and am using the xml writer class to create an xml file that opens as an excel file. I am trying to write out the following but am having difficulty. <Row> <Cell...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.