如何使用C#更改XML文件中元素的屬性?
3 回答

泛舟湖上清波郎朗
TA貢獻(xiàn)1818條經(jīng)驗(yàn) 獲得超3個(gè)贊
如果使用框架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 關(guān)注
- 452 瀏覽
添加回答
舉報(bào)
0/150
提交
取消