XmlNode.RemoveChild(XmlNode) Metode
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Menghapus simpul anak yang ditentukan.
public:
virtual System::Xml::XmlNode ^ RemoveChild(System::Xml::XmlNode ^ oldChild);
public virtual System.Xml.XmlNode RemoveChild(System.Xml.XmlNode oldChild);
abstract member RemoveChild : System.Xml.XmlNode -> System.Xml.XmlNode
override this.RemoveChild : System.Xml.XmlNode -> System.Xml.XmlNode
Public Overridable Function RemoveChild (oldChild As XmlNode) As XmlNode
Parameter
- oldChild
- XmlNode
Simpul yang dihapus.
Mengembalikan
Simpul dihapus.
Pengecualian
oldChild Bukan anak dari simpul ini. Atau simpul ini bersifat baca-saja.
Contoh
Contoh berikut menghapus simpul dari dokumen XML.
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 the title element.
root.RemoveChild(root.FirstChild);
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 the title element.
root.RemoveChild(root.FirstChild)
Console.WriteLine("Display the modified XML...")
doc.Save(Console.Out)
End Sub
End Class
Catatan Bagi Inheritor
Saat mengambil alih di kelas turunan RemoveChild , agar peristiwa dinaikkan dengan benar, Anda harus memanggil RemoveChild metode kelas dasar.