/// <summary> /// To dump the content of a dictionary. /// </summary> /// <param name="dictionary"></param> public static void PrintDictionary(Dictionary <string, string> dictionary) { foreach (KeyValuePair <string, string> kvp in dictionary) { string msg = "key: " + kvp.Key + "=> value: " + kvp.Value; TakaoHelper.msg(msg); } }
/// <summary> /// A helper to generate a dicitonary from a plist(xml) file. /// </summary> /// <param name="filename">The filename of the xml source.</param> /// <returns></returns> public static Dictionary <string, string> DictionaryFromFile(string filename) { Dictionary <string, string> dictionary = new Dictionary <string, string>(); if (System.IO.File.Exists(filename)) { try { XmlTextReader myReader = new XmlTextReader(filename); myReader.XmlResolver = null; string myKey = ""; string myValue = ""; List <string> items = new List <string>(); while (myReader.Read()) { if (myReader.NodeType == XmlNodeType.Element) { if (myReader.Name == "key") { myReader.Read(); myKey = myReader.Value.Trim(); } if (myReader.Name == "array") { if (myReader.IsEmptyElement) { items.Clear(); } else { while (myReader.Read() && !(myReader.NodeType == XmlNodeType.EndElement && myReader.Name == "array")) { if (myReader.NodeType == XmlNodeType.Element && myReader.Name == "string") { myReader.Read(); items.Add(myReader.Value.Trim()); } } } myValue = TakaoHelper.SerializeListToString(items); TakaoHelper.msg(myValue); if (myKey.Length > 0) { dictionary.Add(myKey, myValue); } items.Clear(); myKey = ""; myValue = ""; } if (myReader.Name == "string") { myReader.Read(); myValue = myReader.Value.Trim(); if (myKey.Length > 0) { dictionary.Add(myKey, myValue); } myKey = ""; myValue = ""; } } } myReader.Close(); } catch { } } return(dictionary); }