使用XML读取器读取配置文件 [英] Read config file using XMl reader
本文介绍了使用XML读取器读取配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一堆在我的web.config文件中的AppSettings部分关键。我想读的使用XML技术读者的应用程序设置键和值,并在列表框中填充它们。
I have a bunch of key in AppSettings section of my web.config file. I want to read the key and values of those app settings using XML reader technique and populate them in the list box.
推荐答案
最好的办法就是以检索webconfig值是使用System.Configuration.ConfigurationManager.AppSettings;
The best way is to retrive webconfig values is to use System.Configuration.ConfigurationManager.AppSettings;
要从XML阅读器retrive webconfig值:
To retrive values of webconfig from xml reader:
private void loadConfig()
{
XmlDocument xdoc = new XmlDocument();
xdoc.Load( Server.MapPath("~/") + "web.config");
XmlNode xnodes = xdoc.SelectSingleNode ("/configuration/appSettings");
foreach (XmlNode xnn in xnodes .ChildNodes)
{
ListBox1.Items.Add(xnn.Attributes[0].Value + " = " + xnn.Attributes[1].Value );
}
}
参考:的http://dotnetacademy.blogspot.com/2010/10/read-config-file-using -xml-reader.html
这篇关于使用XML读取器读取配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文