1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
static void Main(string[] args)
{
//創建xml物件
XmlDocument doc = new XmlDocument();
//加載xml
doc.Load("Order.xml");
//拿到item節點
XmlNode xn = doc.SelectSingleNode("/Order/Items");
//刪除item下的所有子節點
xn.RemoveAll();
Console.WriteLine("刪除成功");
//儲存
doc.Save("Order.xml");
Console.WriteLine("儲存成功");
Console.ReadKey();
}
[C# 筆記][XML] 刪除節點
This post is licensed under CC BY 4.0 by the author.