// 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; using System.Text; using System.Xml; public class Cache { private Hashtable english; private Hashtable danish; public Cache() { english = new Hashtable(); danish = new Hashtable(); } private void Process(Hashtable map, XmlNode langroot) { XmlNodeList ctls = langroot.SelectNodes("ctl"); for(int i = 0; i < ctls.Count; i++) { string name = ((XmlElement)(ctls[i])).Attributes["name"].Value; string txt = ctls[i].FirstChild.FirstChild.Value; map.Add(name, txt); } } public void Load(string filename) { XmlDocument doc = new XmlDocument(); doc.Load(filename); Process(english, doc.SelectSingleNode("allctls/english")); Process(danish, doc.SelectSingleNode("allctls/danish")); } public string GetEnglish(string key) { return (string)english[key]; } public string GetDanish(string key) { return (string)danish[key]; } } class TestClass { public static void Main(string[] args) { Cache c = new Cache(); c.Load(@"C:\ctltxt.xml"); Console.WriteLine(c.GetEnglish("Label1")); Console.WriteLine(c.GetEnglish("Button1")); Console.WriteLine(c.GetDanish("Label1")); Console.WriteLine(c.GetDanish("Button1")); } }