一个常用的web.config文件,提供key的值,查询出value的值,因在非WEB项目中使用,请给出直接用XML操作的方式,勿帖System.Configuration.ConfigurationSettings.AppSettings方法,请帮助,万分感激!!!<?xml version='1.0' encoding='utf-8'?>
<configuration>
    <appSettings>
        <add key="CompanyName" value="ABC" />
        <add key="Tel" value="123" />
        ......
    </appSettings>
......
</configuration>

解决方案 »

  1.   

    XmlDocument dom = new XmlDocument();
    dom.Load("web.config.xml");string path = "configuration/appSettings/[@key='Tel']";
    XmlNode node = dom.SelectSingleNode(path);if(node != null) {
       string tel = node.Attribute["Tel"].NodeValue;
    }
      

  2.   

    XmlDocument dom = new XmlDocument();
    dom.Load("web.config.xml");string path = "configuration/appSettings/[@key='Tel']";
    XmlNode node = dom.SelectSingleNode(path);if(node != null) {
       string tel = node.Attributes["Tel"].NodeValue;
    }