Problem with parsing double value from xml file

G

Guest

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 = documentXMLString.DocumentElement;
XmlNodeList records = root.ChildNodes;
XmlAttributeCollection attributes;

for (int i = 0; i < records.Count; i++)
{
attributes = records.Item(i).Attributes;
concept_id=int.Parse(attributes.GetNamedItem("id").InnerText);
rank=double.Parse(attributes.GetNamedItem("rank").InnerText);

concepts_.Add(concept_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.Parse(attributes.GetNamedItem("rank").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
 
C

Chris Taylor

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.ToDouble,
this
will parse the content in accordance with the XSD spec for data types rather
than the current
locale settings.

Hope this helps
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top