如何使用C#更改XML文件中元素的属性?

最佳答案

麦克风;
每次我需要修改XML文档时,都采用这种方式:

//Here is the variable with which you assign a new value to the attribute
string newValue = string.Empty;
XmlDocument xmlDoc = new XmlDocument();

xmlDoc.Load(xmlFile);

XmlNode node = xmlDoc.SelectSingleNode("Root/Node/Element");
node.Attributes[0].Value = newValue;

xmlDoc.Save(xmlFile);

//xmlFile is the path of your file to be modified

希望对你有帮助

关于c# - 如何更改XML属性,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/367730/

10-11 05:34