Click here to Skip to main content
13,297,411 members (65,613 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I need a c# metod that returns the rate based on the desc as an input parameter from this XML file,[^]
i am new to XML, and i have looked at several exampels, but no luck.

Please help

This is what my method looks like so far, dosent work..

        public string test2(string test)
         XmlTextReader reader = new XmlTextReader("");
          if (reader.NodeType == XmlNodeType.Element)
              if (reader.Name == "dailyrates")
                  return reader.GetAttribute(test);
Posted 13-Dec-12 3:50am
Updated 13-Dec-12 4:00am
Richard MacCutchan 13-Dec-12 9:02am
dosent work.
Which is not a very good description. Please edit your post and explain exactly what results you expect and what you get.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

XPath is your friend, here's a small app that fetches the rate from that source;

using System;
using System.Globalization;
using System.Xml;
using System.Xml.XPath;
namespace XmlTest
    class Program
        static decimal GetRate(string code)
            XPathDocument document = new XPathDocument("");
            XPathNavigator navigator = document.CreateNavigator();
            XmlNamespaceManager manager = new XmlNamespaceManager(navigator.NameTable);
            manager.AddNamespace("xsi", "");
            XPathNavigator node = navigator.SelectSingleNode(String.Format("/exchangerates/dailyrates/currency[@code='{0}']/@rate", code), manager);
            return Decimal.Parse(node.Value, NumberStyles.AllowDecimalPoint, CultureInfo.GetCultureInfoByIetfLanguageTag("da-DK"));
        static void Main(string[] args)
            decimal rate = GetRate("EUR");
            Console.WriteLine("Rate=" + rate);

Hope this helps,
Fredrik Bornander
Jesper Schlütter 15-Dec-12 11:46am
Fredrik Bornander 15-Dec-12 11:54am
Glad I could help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.171207.1 | Last Updated 13 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100