小编最近在工作中做了一个小功能
string FilePath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + ".//" + "DB.config"; var doc = new XmlDocument(); doc.Load(FilePath); var selectSingleNode = doc.SelectSingleNode("//appSettings"); if (selectSingleNode != null) { var nodeList = selectSingleNode.ChildNodes; int count = 0; foreach (var xn in nodeList) { XmlElement xe; try { xe = (XmlElement)xn; } catch { continue; } string keyName = xe.GetAttribute("key"); string keyValue = xe.GetAttribute("value"); }