////// 返回XMl文件指定元素的指定属性值 /// /// 指定元素 /// 指定属性 ///public static string getXmlValue(string xmlElement, string xmlAttribute) { var Current = Directory.GetCurrentDirectory();//获取当前根目录 XDocument xmlDoc = XDocument.Load(Current + "/config.xml"); var results = from c in xmlDoc.Descendants(xmlElement) select c; string s = ""; foreach (var result in results) { s = result.Attribute(xmlAttribute).Value.ToString(); } return s; } /// /// 设置XMl文件指定元素的指定属性的值 /// /// 指定元素 /// 指定属性 /// 指定值 public static void setXmlValue(string xmlElement, string xmlAttribute, string xmlValue) { var Current = Directory.GetCurrentDirectory();//获取当前根目录 XDocument xmlDoc = XDocument.Load(Current + "/config.xml"); xmlDoc.Element("Soft").Element(xmlElement).Attribute(xmlAttribute).SetValue(xmlValue); xmlDoc.Save(Current + "/config.xml"); }