1 using System; 2 using System.Collections.Generic; 3 using System.Xml; 4 5 namespace COMMON 6 { 7 public class XmlHelperClass 8 { 9 public void Read() 10 { 11 Dictionary<string, string> m_FontList = new Dictionary<string, string>(); 12 try 13 { 14 XmlDocument doc = new XmlDocument(); 15 16 // 获得配置文件的全路径 17 string strFileName = "Font.xml"; 18 doc.Load(strFileName); 19 XmlNode node = doc.GetElementById("font"); 20 XmlNodeList nodes = node.ChildNodes; 21 for (int i = 0; i < nodes.Count; i++) 22 { 23 if (nodes[i].NodeType == XmlNodeType.Element) 24 { 25 m_FontList[nodes[i].Name] = nodes[i].InnerText; 26 } 27 } 28 } 29 catch (Exception e) 30 { 31 throw e; 32 } 33 } 34 35 public void Write(string tagName, string value) 36 { 37 XmlDocument doc = new XmlDocument(); 38 39 //获得配置文件的全路径 40 string strFileName = @"C:Program FilesIIS Express/Font.xml"; 41 doc.Load(strFileName); 42 XmlNode node = doc.GetElementById("font"); 43 XmlNodeList nodes = node.ChildNodes; 44 for (int i = 0; i < nodes.Count; i++) 45 { 46 if (nodes[i].Name.Equals(tagName)) 47 { 48 nodes[i].InnerText = value; 49 } 50 } 51 try 52 { 53 //保存上面的修改 54 doc.Save(strFileName); 55 56 } 57 catch (Exception e) 58 { 59 throw e; 60 } 61 } 62 } 63 }