I have created a function that reads a third party XML document to get the conversion rate of Euros to GBP on any given date, however my linq query is returning a null value.
XML:
<therate xmlns="http://somecurrencysite.com">
<terms>someValue</terms>
<from>EUR</from>
<amount>1.0</amount>
<timestamp>2001-05-01T06:00:00Z</timestamp>
<to>
<rate>
<currency>GBP</currency>
<dayrate>0.619887217</dayrate>
</rate>
</to>
</therate>
C#:
var uri = "http://somecurrencysite.com?date=" + date.ToString("yyyy-MM-dd") + "&to=GBP";
decimal rate;
using (var client = new WebClient())
{
client.Credentials = new NetworkCredential("userName", "passWord");
try
{
var source = new MemoryStream(client.DownloadData(uri));
var xRdr = new XmlTextReader(source);
rate = XDocument.Load(xRdr)
.Descendants("rate")
.Select(e => (decimal)e.Element("dayrate"))
.FirstOrDefault();
}
catch (Exception ex)
{
Err.ErrMsg(ex);
throw;
}
}
return rate;
Please could someone help me figure out what I'm missing here,
Cheers.