// 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(int nodays, 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(); for(int i = 0; i < nodays; i++) { string ratestr = doc.SelectSingleNode("/gesmes:Envelope/default:Cube/default:Cube[" + (i + 1) + "]/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(2, "USD")) { Console.WriteLine(d); } } } }