473,382 Members | 1,362 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,382 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 6879


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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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
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...

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.