当前位置:编程学习 > XML/UML >>

如何从XML文件里面读取配置文件

    public string GetConStr()
    {
        try
        {

            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(Server.MapPath("App_Data\config.xml"));
            XmlNode node1 = xmlDoc.SelectSingleNode("configuration/ConnectionStrings1/DataSource");
            XmlNode node2 = xmlDoc.SelectSingleNode("configuration/ConnectionStrings1/uid");
            XmlNode node3 = xmlDoc.SelectSingleNode("configuration/ConnectionStrings1/pwd");
            string strcon = "Data Source=" + node1.InnerText + ";uid=" + node2.InnerText + ";pwd=" + node3.InnerText;
            return strcon;
        }
        catch
        {
            Response.Redirect("Config.aspx");
            return null;
        }
    }

 

调用

IConfig iconfig = new IConfig();

iconfig .GetConStr();

    
补充:软件开发 , C# ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,