-1

I want to read Bank of Canada XML response to get the closing rates of each currency. But they have very complex XML Response, you can check at

Visit www.bankofcanada.ca/stats/assets/rates_rss/closing/en_all.xml

I'm trying my old way for parsing XML but that work's fine only with simple XML i.e

  var url ="http://www.bankofcanada.ca/stats/assets/rates_rss/closing/en_all.xml";
        var uploadResult = CurrencyAPI.TriggerApiAction(url);
        XDocument xDoc = XDocument.Parse(CurrencyAPI.backstr);



        foreach (var download in xDoc.Descendants("cb:exchangeRate"))
        {
            a1 = download.Element("cb:value").Value;
            a2 = download.Element("cb:baseCurrency").Value;
            a3 = download.Element("cb:targetCurrency").Value;
        }

Please help me with this Thanks

0

1 Answer 1

0
XNamespace cb = "http://www.cbwiki.net/wiki/index.php/Specification_1.1";
foreach (var download in xDoc.Descendants(cb+"exchangeRate"))
{
    var a1 = download.Element(cb+"value").Value;
    var a2 = download.Element(cb+"baseCurrency").Value;
    var a3 = download.Element(cb+"targetCurrency").Value;
}

Or better:

XNamespace cb = "http://www.cbwiki.net/wiki/index.php/Specification_1.1";
foreach (var download in xDoc.Descendants(cb+"exchangeRate"))
{
    var a1 = (decimal)download.Element(cb+"value");
    var a2 = (string)download.Element(cb+"baseCurrency");
    var a3 = (string)download.Element(cb+"targetCurrency");
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.