修改xml文件时报错,等待解决
调用的方法如下xml.UpdateElement(Server.MapPath("~/Roles.xml"), dd.Parent.Value.ToString().Substring(1), Eprelimits, "name", dd.Text)
public void UpdateElement(string path, string node_root, string new_text, string att_name, string att_value)
{
XmlReaderSettings settings = new XmlReaderSettings();
settings.IgnoreComments = true;
XmlReader reader = XmlReader.Create(path, settings);
XmlDocument xmlDoc1 = new XmlDocument();
xmlDoc1.Load(reader);
LoadFunNode(xmlDoc1.DocumentElement,new_text,att_name,att_value,path,xmlDoc1);
}
private void LoadFunNode(XmlNode xmlnode, string new_text, string att_name, string att_value,string path,XmlDocument xmlDoc1)
{
foreach (XmlElement xe in xmlnode.ChildNodes)
{
if (xe.ChildNodes.Count > 0)
{
LoadFunNode(xe, new_text, att_name, att_value,path,xmlDoc1);
}
if (xe.GetAttribute(att_name) == att_value)
{
xe.SetAttribute("Value", new_text); //内容赋值
break;
}
}
xmlDoc1.Save(path);//保存
}
每次运行到绿色那行代码的时候提示,文件正被另一个程序使用。该如何解决在线等 --------------------编程问答-------------------- public void UpdateElement(string path, string node_root, string new_text, string att_name, string att_value)
{
XmlReaderSettings settings = new XmlReaderSettings();
settings.IgnoreComments = true;
XmlReader reader = XmlReader.Create(path, settings);
XmlDocument xmlDoc1 = new XmlDocument();
xmlDoc1.Load(reader);
LoadFunNode(xmlDoc1.DocumentElement,new_text,att_name,att_value,path,xmlDoc1);
xmlDoc1.Save(path);//保存 放到这里看看呢,不知道是不是你用了递归的问题
}
--------------------编程问答--------------------
--------------------编程问答--------------------
补充:.NET技术 , C#