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

Public Overridable Function InsertBefore ( _ newChild As XmlNode, _ refChild As XmlNode _ ) As XmlNode
Dim instance As XmlNode Dim newChild As XmlNode Dim refChild As XmlNode Dim returnValue As XmlNode returnValue = instance.InsertBefore(newChild, refChild)
- newChild
挿入する XmlNode。
挿入されるノード。


refChild が null 参照 (Visual Basic では Nothing) の場合は、子ノードのリストの末尾に newChild を挿入します。newChild が XmlDocumentFragment オブジェクトの場合は、その子ノードが同じ順序で refChild の前に挿入されます。newChild が既にツリーに存在する場合は、最初に削除されます。
別のドキュメントで作成されたノードを挿入する場合は、XmlDocument.ImportNode を使用してそのノードを現在のドキュメントにインポートできます。インポートされたノードは次に、現在のドキュメントに挿入できます。
継承時の注意 派生クラスで InsertBefore をオーバーライドする場合は、イベントを正常に発生させるために、基本クラスの InsertBefore メソッドを呼び出す必要があります。
新しいノードを XML ドキュメントに追加する例を次に示します。
Option Strict Option Explicit 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 node. Dim elem As XmlElement = doc.CreateElement("price") elem.InnerText = "19.95" 'Add the node to the document. root.InsertBefore(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 node. XmlElement elem = doc.CreateElement("price"); elem.InnerText="19.95"; //Add the node to the document. root.InsertBefore(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 node. XmlElement^ elem = doc->CreateElement( "price" ); elem->InnerText = "19.95"; //Add the node to the document. root->InsertBefore( 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 node. XmlElement elem = doc.CreateElement("price"); elem.set_InnerText("19.95"); //Add the node to the document. root.InsertBefore(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.InsertBefore メソッドを検索する場合は、下記のリンクをクリックしてください。

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