Asp.Net 读取xml文件中Key的值,并且过滤掉注释内容代码
时间:2014-05-01 15:56:57
收藏:0
阅读:391
/// <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; }
评论(0)