Home [C# 筆記][XML] 刪除節點
Post
Cancel

[C# 筆記][XML] 刪除節點

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();
}

https://www.bilibili.com/video/BV1vG411A7my?p=64

This post is licensed under CC BY 4.0 by the author.