项目中经常遇到一些读取xml文件的方法,特别是在进行错误处理的情况下,要根据ErrId来获取Error内容,网上这一方面的东西比较零散,今天花了点时间整理了一下,写了一个小例子,拿来和大家分享一下。 首先建立一个共同的类,代码如下: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml; using System.IO; namespace XmlRead { public class Common { public static bool GetMessageByKey(string xmlPath, string AppKey, out string AppValue) { bool isSuccess = true; AppValue = ""; if (!IsXmlFlieExist(xmlPath)) { return false; } try { XmlDocument xDoc = new XmlDocument(); xDoc.Load(xmlPath); XmlNode xNode; XmlElement xElem1; xNode = xDoc.SelectSingleNode("//appSettings"); xEl