如何从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# ,