如何使用C#更改XML文件中元素的属性?
3 回答
Helenr
TA贡献1780条经验 获得超4个赞
如果使用框架3.5,则使用LINQ to xml:
using System.Xml.Linq;
XDocument xmlFile = XDocument.Load("books.xml");
var query = from c in xmlFile.Elements("catalog").Elements("book")
select c;
foreach (XElement book in query)
{
book.Attribute("attr1").Value = "MyNewValue";
}
xmlFile.Save("books.xml");
- 3 回答
- 0 关注
- 355 浏览
添加回答
举报
0/150
提交
取消