XmlNode.RemoveAll 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
移除目前節點的所有子節點和/或屬性。
public:
virtual void RemoveAll();
public virtual void RemoveAll();
abstract member RemoveAll : unit -> unit
override this.RemoveAll : unit -> unit
Public Overridable Sub RemoveAll ()
範例
以下範例將所有子節點與屬性節點從根節點中移除。
using System;
using System.IO;
using System.Xml;
public class Sample {
public static void Main() {
XmlDocument doc = new XmlDocument();
doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" +
"<title>Pride And Prejudice</title>" +
"</book>");
XmlNode root = doc.DocumentElement;
//Remove all attribute and child nodes.
root.RemoveAll();
Console.WriteLine("Display the modified XML...");
doc.Save(Console.Out);
}
}
Option Explicit
Option Strict
Imports System.IO
Imports System.Xml
Public Class Sample
Public Shared Sub Main()
Dim doc As New XmlDocument()
doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" & _
"<title>Pride And Prejudice</title>" & _
"</book>")
Dim root As XmlNode = doc.DocumentElement
'Remove all attribute and child nodes.
root.RemoveAll()
Console.WriteLine("Display the modified XML...")
doc.Save(Console.Out)
End Sub
End Class
備註
如果已知已移除的屬性有預設值,則會立即出現一個包含預設值的屬性,並在適用時包含對應的命名空間 URI、本地名稱和前綴。
此方法是 Microsoft 對文件物件模型(DOM)的擴充。
給繼承者的注意事項
在導出類別中覆 RemoveAll 寫時,為了正確引發事件,必須呼叫 RemoveAll 基底類別的方法。