您的位置:首页 > 编程语言 > C#

C#操作XML文档

2013-05-17 19:42 369 查看
网站配置文件Web.config是一xml文件,在对其进行配置时,可采用对一般xml文件进行操作的方式。

XmlDocument xmldoc = new XmlDocument();
string filename = Server.MapPath("..//") + "Web.config";
xmldoc.Load(filename);
XmlNode root = xmldoc.SelectSingleNode("configuration");
XmlNode conNode = root.SelectSingleNode("connectionStrings");
XmlNodeList conNodeList = conNode.ChildNodes;
foreach (XmlNode node in conNodeList)
{
XmlElement element = (XmlElement)node;

if (element.GetAttribute("providerName") == "System.Data.OleDb")
{

element.SetAttribute("connectionString", sb.ToString());

element.SetAttribute("name", "connectionString");
}
xmldoc.Save(filename);
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: