473,653 Members | 2,955 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with parsing double value from xml file

Hello,

I´ve a problem with parsing a double value from an xml file.

My code looks like this:

int concept_id;
double rank;
XmlElement root = documentXMLStri ng.DocumentElem ent;
XmlNodeList records = root.ChildNodes ;
XmlAttributeCol lection attributes;

for (int i = 0; i < records.Count; i++)
{
attributes = records.Item(i) .Attributes;
concept_id=int. Parse(attribute s.GetNamedItem( "id").InnerText );
rank=double.Par se(attributes.G etNamedItem("ra nk").InnerText) ;

concepts_.Add(c oncept_id, rank);
}
The variable concepts_ is a Hashtable.

A typical XML file looks like this:

<root>
<concept id="20114" rank="1" />
<concept id="13786" rank="0.5" />
</root>

The problem is with parsing the double value:
rank=double.Par se(attributes.G etNamedItem("ra nk").InnerText) ;

For example with:
<concept id="13786" rank="0.5" />
the rank is parsed as "5.0" instead of "0.5"
Do you have any idea what happens?
Regards,

Martin

Oct 3 '06 #1
1 3697
Hi,

What are your current regional settings, specifically the decimal and
thousands separator?

When working with XML I would suggest that you use the XmlConvert.ToDo uble,
this
will parse the content in accordance with the XSD spec for data types rather
than the current
locale settings.

Hope this helps

--
Chris Taylor
http://dotnetjunkies.com/weblog/chris.taylor
"Martin Pöpping" <ma******@despa mmed.comwrote in message
news:ef******** **@newsreader2. netcologne.de.. .
Hello,

I´ve a problem with parsing a double value from an xml file.

My code looks like this:

int concept_id;
double rank;
XmlElement root = documentXMLStri ng.DocumentElem ent;
XmlNodeList records = root.ChildNodes ;
XmlAttributeCol lection attributes;

for (int i = 0; i < records.Count; i++)
{
attributes = records.Item(i) .Attributes;
concept_id=int. Parse(attribute s.GetNamedItem( "id").InnerText );
rank=double.Par se(attributes.G etNamedItem("ra nk").InnerText) ;

concepts_.Add(c oncept_id, rank);
}
The variable concepts_ is a Hashtable.

A typical XML file looks like this:

<root>
<concept id="20114" rank="1" />
<concept id="13786" rank="0.5" />
</root>

The problem is with parsing the double value:
rank=double.Par se(attributes.G etNamedItem("ra nk").InnerText) ;

For example with:
<concept id="13786" rank="0.5" />
the rank is parsed as "5.0" instead of "0.5"
Do you have any idea what happens?
Regards,

Martin

Oct 3 '06 #2

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

Similar topics

1
4902
by: nooy66 | last post by:
I need to read value type double form my binary file. When i use Hex Workshop software read my binary file. i have data 8 bytes : hex = 3131 3131 3131 3140 string = 1111111@ Float = 2.5784852e-009 Double = 17.192157 When i use php to read file by code:
1
2645
by: San | last post by:
Hi, I'm using a Managed C++ project with MFC support. I have an ArrayList pointer object alValue (ArrayList* alValue) to this object i want to add all the elements present in Vector<double> vVector to it.. I'm using this line of code.. alValue->Add (new System::Double(vVector)) and I'm getting the following compilation error..
4
1527
by: Max80 | last post by:
Hi Everyone, I have a double value (e.g. 2.00) which I would like to convert to string. Simply returning the value using the .ToString() method trims the 0s after the decimal point. I know that its is possible by doing the following double d1 = 2.00; string strValue; strValue = d1.ToString("#,###.00") However the problem is that I do not know how many 0s there will be after the decimal point before hand. The number...
5
2330
by: moddster | last post by:
Hi Guys. I am a newbie to perl and need some help with a problem. PROBLEM: I have to parse an HTML file and get rid of all the HTML tags and count the number of sumbissions a person has through out the dates found. The condition is that multiple submissions by the same person on the same date is counted as 1. I have already gotten rid of the HTML tags using: #!/usr/bin/perl -w use strict;
4
2366
by: ashishbhatt12 | last post by:
Hi all, i have a problem in the value which stored in memory location.i want to convert it into the double value. Suppose, i have the value int k = 2; when I write it on the memory location like, it is like .. 40 00 00 00 00 00 00 00
2
1580
by: treybraid | last post by:
My Flash file is a GameCenter where team standings are kept.. I have it set up right now with the master spreadsheet programmed that is linked to a dummy sheet that is saved as a CVS doc and loaded into my flash document. it is working great; but, there has got to be an easier way to do this- at some point I will not be the one doing the editing/ updating; so, I need this process streamlined. Ideally I am looking for someone to update the...
2
1752
by: blazzer | last post by:
Hi, I need help. I just wondering whether i can set the double value using random class..i even use if statement to set it..but nothing..i wanna set between 0.5 n 0.7 value.. double planetMass = 0.0; double sunMass = 0.0; Random rdm = new Random(); double rand = rdm.nextDouble(); if (rand >= 0.5 && rand <= 0.7){
3
4592
by: =?Utf-8?B?RGFuYQ==?= | last post by:
I am re-posting this message after registering my posting alias. When I specify an end tag for the clear element of namespaces in my web.config file, the parser error "Unrecognized element 'add'" is reported. .... <pages> <namespaces> <clear></clear> <add namespace="System"/>
1
1768
by: raghudr | last post by:
Hi all, I am parsing an .xml file.My main intention is to retrieve the field value:- "Name Value" which is "rag" and store it in a List. Fot that i wrote code like this: //i am using dataset method to read the .xml files
0
8370
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
8470
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8590
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7302
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6160
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5620
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4147
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2707
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1591
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.