/// <summary> /// Load an XML file /// </summary> /// <param name="fileName">file name</param> public void Load(string fileName) { this.table.Clear(); XmlDocument doc = new XmlDocument(); doc.PreserveWhitespace = false; doc.Load(fileName); XmlNodeList nodes = doc.SelectNodes("/Dictionnaire/value"); foreach (XmlNode node in nodes) { string name; string typeName; name = node.Attributes.GetNamedItem("name").Value; typeName = node.Attributes.GetNamedItem("type").Value; if (String.Compare(typeName, "string", true) == 0) { Chaine c = new Chaine(); c.Value = node.InnerText; this.table.Add(name, c); } else if (String.Compare(typeName, "array") == 0) { Array a = new Array(); a.Load(node); this.table.Add(name, a); } } }
/// <summary> /// Sets the value of an existing string /// Do nothing if not exists or is not a string /// </summary> /// <param name="name">name</param> /// <param name="value">value</param> public void SetString(string name, string value) { if (this.IsString(name)) { Chaine c = this.table[name] as Chaine; c.Value = value; } }
/// <summary> /// Gets a string from a name /// </summary> /// <param name="name">name</param> /// <returns>the string or null if not found</returns> public string GetString(string name) { if (this.IsString(name)) { Chaine c = this.table[name] as Chaine; return(c.Value); } else { return(null); } }
/// <summary> /// Add a new string /// replace if string already exists /// </summary> /// <param name="name">name</param> /// <param name="value">value</param> public void AddString(string name, string value) { Chaine c = new Chaine(); c.Value = value; if (this.Exists(name)) { this.table[name] = c; } else { this.names = null; this.table.Add(name, c); } }