XmlNode.ReplaceChild メソッド
アセンブリ: System.Xml (system.xml.dll 内)

Public Overridable Function ReplaceChild ( _ newChild As XmlNode, _ oldChild As XmlNode _ ) As XmlNode
Dim instance As XmlNode Dim newChild As XmlNode Dim oldChild As XmlNode Dim returnValue As XmlNode returnValue = instance.ReplaceChild(newChild, oldChild)
戻り値
置き換えられたノード。


newChild が既にツリーに存在する場合は、最初に削除されます。
newChild が別のドキュメントで作成された場合は、XmlDocument.ImportNode を使用して、現在のドキュメントにそのノードをインポートします。インポートされたノードは次に、ReplaceChild メソッドに渡すことができます。
継承時の注意 派生クラスで ReplaceChild をオーバーライドする場合は、イベントを正常に発生させるために、基本クラスの ReplaceChild メソッドを呼び出す必要があります。
XML ドキュメントのタイトル要素を置き換える例を次に示します。
Imports System 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 'Main End Class 'Sample
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); } }
#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 ); }
import System.*; import System.IO.*; import System.Xml.*; public class Sample { public static void main(String[] args) { XmlDocument doc = new XmlDocument(); doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" + "<title>Pride And Prejudice</title>" + "</book>"); XmlNode root = doc.get_DocumentElement(); //Create a new title element. XmlElement elem = doc.CreateElement("title"); elem.set_InnerText("The Handmaid's Tale"); //Replace the title element. root.ReplaceChild(elem, root.get_FirstChild()); Console.WriteLine("Display the modified XML..."); doc.Save(Console.get_Out()); } //main } //Sample

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からXmlNode.ReplaceChild メソッドを検索する場合は、下記のリンクをクリックしてください。

- XmlNode.ReplaceChild メソッドのページへのリンク