// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Globalization; using System.Xml; namespace E { public class Program { public static decimal GetRate(DateTime date, string currency) { string datestr = date.ToString("yyyy-MM-dd"); XmlDocument doc = new XmlDocument(); doc.Load("http://www.nationalbanken.dk/_vti_bin/DN/DataService.svc/CurrencyRatesHistoryXML?lang=da"); XmlNamespaceManager xnm = new XmlNamespaceManager(doc.NameTable); xnm.AddNamespace("gesmes", "http://www.gesmes.org/xml/2002-08-01"); xnm.AddNamespace("default", "http://www.ecb.int/vocabulary/2002-08-01/eurofxref"); string ratestr = doc.SelectSingleNode("/gesmes:Envelope/default:Cube/default:Cube[@time='" + datestr + "']/default:Cube[@currency='" + currency + "']/@rate", xnm).Value; return decimal.Parse(ratestr, new CultureInfo("da-DK", false)); } public static void Main(string[] args) { Console.WriteLine(GetRate(DateTime.Now, "USD")); Console.WriteLine(GetRate(DateTime.Now.AddDays(-1), "USD")); } } }