XmlNode.InsertAfter(XmlNode, XmlNode) 메서드
정의
지정된 노드를 지정된 참조 노드 바로 다음에 삽입합니다.Inserts the specified node immediately after the specified reference node.
public:
virtual System::Xml::XmlNode ^ InsertAfter(System::Xml::XmlNode ^ newChild, System::Xml::XmlNode ^ refChild);
public virtual System.Xml.XmlNode InsertAfter (System.Xml.XmlNode newChild, System.Xml.XmlNode refChild);
abstract member InsertAfter : System.Xml.XmlNode * System.Xml.XmlNode -> System.Xml.XmlNode
override this.InsertAfter : System.Xml.XmlNode * System.Xml.XmlNode -> System.Xml.XmlNode
Public Overridable Function InsertAfter (newChild As XmlNode, refChild As XmlNode) As XmlNode
매개 변수
- newChild
- XmlNode
삽입할 노드입니다.The node to insert.
- refChild
- XmlNode
참조 노드입니다.The reference node. newChild
는 refChild
뒤에 삽입됩니다.newChild
is placed after refChild
.
반환
삽입할 노드입니다.The node being inserted.
예외
이 노드가 newChild
노드 형식의 자식 노드를 허용하지 않는 형식을 가지는 경우This node is of a type that does not allow child nodes of the type of the newChild
node.
newChild
가 이 노드의 상위 노드일 경우The newChild
is an ancestor of this node.
이 노드를 만든 문서가 아닌 다른 문서에서 newChild
를 만든 경우The newChild
was created from a different document than the one that created this node.
refChild
가 이 노드의 자식이 아닌 경우The refChild
is not a child of this node.
이 노드가 읽기 전용인 경우This node is read-only.
예제
다음 예제에서는 XML 문서에 새 노드를 추가 합니다.The following example adds a new node to 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;
//Create a new node.
XmlElement^ elem = doc->CreateElement( "price" );
elem->InnerText = "19.95";
//Add the node to the document.
root->InsertAfter( 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 node.
XmlElement elem = doc.CreateElement("price");
elem.InnerText="19.95";
//Add the node to the document.
root.InsertAfter(elem, root.FirstChild);
Console.WriteLine("Display the modified XML...");
doc.Save(Console.Out);
}
}
Option Strict
Option Explicit
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.InsertAfter(elem, root.FirstChild)
Console.WriteLine("Display the modified XML...")
doc.Save(Console.Out)
End Sub
End Class
설명
하는 경우 refChild
됩니다 null
, 삽입 newChild
자식 노드 목록 맨 앞에 있습니다.If refChild
is null
, insert newChild
at the beginning of the list of child nodes. 모든 내용을 합니다 newChild
삽입 되 면 동일한 순서로 후 refChild
합니다.All the contents of the newChild
are inserted, in the same order, after refChild
. 경우는 newChild
는 이미 트리에서 원래 위치에서 제거 하 고 대상 위치에 추가 합니다.If the newChild
is already in the tree, it is removed from its original position and added to its target position. 노드를 삽입 하는 방법에 대 한 자세한 내용은 참조 하세요. XML 문서에 노드 삽입합니다.For more information about inserting nodes, see Inserting Nodes into an XML Document.
삽입 하는 노드가 다른 문서에서 생성 된 경우 사용할 수 있습니다 XmlDocument.ImportNode 현재 문서에 노드를 가져오려고 합니다.If the node being inserted was created from another document, you can use XmlDocument.ImportNode to import the node to the current document. 현재 문서에 삽입한 다음 가져온된 노드를 사용할 수 있습니다.The imported node can then be inserted into the current document.
이 메서드는 문서 개체 모델 (DOM)에 대 한 Microsoft 확장입니다.This method is a Microsoft extension to the Document Object Model (DOM).
상속자 참고
재정의 하는 경우 InsertAfter
파생된 클래스에서 올바르게 발생할 이벤트를 위해 호출 해야 합니다는 InsertAfter
메서드의 기본 클래스입니다.When overriding InsertAfter
in a derived class, in order for events to be raised correctly, you must call the InsertAfter
method of the base class.