Asp.Net 读取xml文件中Key的值,并且过滤掉注释内容代码

时间:2014-05-01 15:56:57   收藏:0   阅读:391
mamicode.com,码迷
      /// <summary>
        /// 读取配置文件keys
        /// </summary>
        /// <returns></returns>
        public string _GetKeys()
        {
            string filename = Server.MapPath("/") + @"web.config";
            XmlDocument xmldoc = new XmlDocument();
            XmlReaderSettings settings = new XmlReaderSettings();
            settings.IgnoreComments = true;
            settings.IgnoreWhitespace = true;
            XmlReader reader = XmlReader.Create(filename, settings);
            xmldoc.Load(reader);
            XmlNodeList topM = xmldoc.DocumentElement.ChildNodes;
            foreach (XmlElement element in topM)
            {
                if (element.Name == "appSettings")
                {
                    XmlNodeList node = element.ChildNodes;
                    if (node.Count > 0)
                    {
                        foreach (XmlElement el in node)
                        {
                            string str = el.Attributes["key"].Value.ToString();
                            AppConfigKeys += str.ToString() + ",";
                        }
                    }
                }
            }
            return AppConfigKeys;
        }
mamicode.com,码迷

 

Asp.Net 读取xml文件中Key的值,并且过滤掉注释内容代码,码迷,mamicode.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!