复制代码 代码如下:
C#代码:
复制代码 代码如下:
Xmldocument xml = new Xmldocument();
xml.Load(context.Server.MapPath("~/js/XMLFile.xml"));
XmlNode xn = xml.documentElement;
foreach (XmlNode node in xn.ChildNodes)
{
if (node.Name == "info")
{
node["content"].InnerText = content;
node["speed"].InnerText = speed;
node["color"].InnerText = color;
}
}
xml.Save(context.Server.MapPath("~/js/XMLFile.xml"));
另外两种办法:
修改xml字符串的某个节点的属性值,如下:
复制代码 代码如下:
Xmldocument doc = new Xmldocument();
doc.LoadXml("
XmlAttribute att =(XmlAttribute)doc.SelectSingleNode("/fsdlconfig/@userName");
Console.WriteLine(att.Value);
att.Value = "test";
string str = doc.OuterXml;
节点userName的值由原来的"ss",变成了"test",然后用doc.OuterXml保存修改后的xml为字符串。
另一种方式:
复制代码 代码如下:
Xmldocument doc = new Xmldocument();
doc.LoadXml("
XmlElement att = (XmlElement)doc.FirstChild;
att.SetAttribute("userName","test");
string str = doc.OuterXml;



