Problem with parsing double value from xml file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Martin Pöpping

    #1

    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

  • Chris Taylor

    #2
    Re: Problem with parsing double value from xml file

    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

    "Martin Pöpping" <martin_p@despa mmed.comwrote in message
    news:efu4ig$849 $1@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
    >

    Comment

    Working...