XmlNode.RemoveAll Metode

Definisi

Menghapus semua simpul anak dan/atau atribut simpul saat ini.

public:
 virtual void RemoveAll();
public virtual void RemoveAll();
abstract member RemoveAll : unit -> unit
override this.RemoveAll : unit -> unit
Public Overridable Sub RemoveAll ()

Contoh

Contoh berikut menghapus semua simpul anak dan atribut dari simpul akar.

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

Keterangan

Jika atribut yang dihapus diketahui memiliki nilai default, atribut segera muncul yang berisi nilai default dan, jika berlaku, URI namespace yang sesuai, nama lokal, dan awalan.

Metode ini adalah ekstensi Microsoft ke Model Objek Dokumen (DOM).

Catatan Bagi Inheritor

Saat mengambil alih di kelas turunan RemoveAll , agar peristiwa dinaikkan dengan benar, Anda harus memanggil RemoveAll metode kelas dasar.

Berlaku untuk