当前位置:编程学习 > 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 © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,