C# 解析XML

来源:互联网 发布:成都英创 linux gpio 编辑:程序博客网 时间:2024/06/05 16:39

  小编最近在工作中做了一个小功能

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");                }


原创粉丝点击