// 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.Collections.Generic; using System.Globalization; using System.Xml; namespace E { public class Program { private static readonly CultureInfo dadk = new CultureInfo("da-DK", false); public static List GetRate(List date, string currency) { 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"); List res = new List(); foreach(DateTime dt in date) { string datestr = dt.ToString("yyyy-MM-dd"); string ratestr = doc.SelectSingleNode("/gesmes:Envelope/default:Cube/default:Cube[@time='" + datestr + "']/default:Cube[@currency='" + currency + "']/@rate", xnm).Value; res.Add(decimal.Parse(ratestr, dadk)); } return res; } public static void Main(string[] args) { foreach(decimal d in GetRate(new List { DateTime.Now, DateTime.Now.AddDays(-1) }, "USD")) { Console.WriteLine(d); } } } }