XmlNode.ReplaceChild(XmlNode, XmlNode) Yöntem
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Alt düğümü düğümle oldChild newChild değiştirir.
public:
virtual System::Xml::XmlNode ^ ReplaceChild(System::Xml::XmlNode ^ newChild, System::Xml::XmlNode ^ oldChild);
public virtual System.Xml.XmlNode ReplaceChild (System.Xml.XmlNode newChild, System.Xml.XmlNode oldChild);
abstract member ReplaceChild : System.Xml.XmlNode * System.Xml.XmlNode -> System.Xml.XmlNode
override this.ReplaceChild : System.Xml.XmlNode * System.Xml.XmlNode -> System.Xml.XmlNode
Public Overridable Function ReplaceChild (newChild As XmlNode, oldChild As XmlNode) As XmlNode
Parametreler
- newChild
- XmlNode
Alt listeye yerleştirecek yeni düğüm.
- oldChild
- XmlNode
Listede değiştirilen düğüm.
Döndürülenler
Düğüm değiştirildi.
Özel durumlar
Bu düğüm, düğüm türünün alt düğümlerine izin vermeyen bir türdür newChild .
newChild bu düğümün bir atasıdır.
, newChild bu düğümü oluşturan belgeden farklı bir belgeden oluşturuldu.
Bu düğüm salt okunurdur.
oldChild bu düğümün alt öğesi değil.
Örnekler
Aşağıdaki örnek, XML belgesindeki başlık öğesinin yerini alır.
#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;
//Create a new title element.
XmlElement^ elem = doc->CreateElement( "title" );
elem->InnerText = "The Handmaid's Tale";
//Replace the title element.
root->ReplaceChild( elem, 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;
//Create a new title element.
XmlElement elem = doc.CreateElement("title");
elem.InnerText="The Handmaid's Tale";
//Replace the title element.
root.ReplaceChild(elem, root.FirstChild);
Console.WriteLine("Display the modified XML...");
doc.Save(Console.Out);
}
}
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
'Create a new title element.
Dim elem As XmlElement = doc.CreateElement("title")
elem.InnerText = "The Handmaid's Tale"
'Replace the title element.
root.ReplaceChild(elem, root.FirstChild)
Console.WriteLine("Display the modified XML...")
doc.Save(Console.Out)
End Sub
End Class
Açıklamalar
newChild zaten ağaçtaysa, önce kaldırılır.
newChild başka bir belgeden oluşturulduysa, düğümünü geçerli belgeye aktarmak için kullanabilirsinizXmlDocument.ImportNode. İçeri aktarılan düğüm daha sonra yöntemine ReplaceChild geçirilebilir.
Devralanlara Notlar
Türetilmiş bir sınıfta geçersiz kılma ReplaceChild sırasında, olayların doğru şekilde tetiklenmesi için temel sınıfın ReplaceChild yöntemini çağırmanız gerekir.