XmlNode.RemoveChild(XmlNode) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Removes specified child node.
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
Parameters
- oldChild
- XmlNode
The node being removed.
Returns
The node removed.
Exceptions
The oldChild
is not a child of this node. Or this node is read-only.
Examples
The following example removes a node from the XML document.
#using <System.Xml.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
XmlDocument^ doc = gcnew 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 );
}
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
Notes to Inheritors
When overriding RemoveChild
in a derived class, in order for events to be raised correctly, you must call the RemoveChild
method of the base class.
Applies to
Współpracuj z nami w serwisie GitHub
Źródło tej zawartości można znaleźć w witrynie GitHub, gdzie można również tworzyć i przeglądać problemy i żądania ściągnięcia. Więcej informacji znajdziesz w naszym przewodniku dla współtwórców.