XmlElement.CloneNode(Boolean) XmlElement.CloneNode(Boolean) XmlElement.CloneNode(Boolean) XmlElement.CloneNode(Boolean) Method

정의

이 노드의 복제본을 만듭니다.Creates a duplicate of this node.

public:
 override System::Xml::XmlNode ^ CloneNode(bool deep);
public override System.Xml.XmlNode CloneNode (bool deep);
override this.CloneNode : bool -> System.Xml.XmlNode
Public Overrides Function CloneNode (deep As Boolean) As XmlNode

매개 변수

deep
Boolean Boolean Boolean Boolean

지정된 노드 아래의 하위 트리를 재귀적으로 복제하려면 true이고, 노드 자체(노드가 XmlElement인 경우 해당 특성)만 복제하려면 false입니다.true to recursively clone the subtree under the specified node; false to clone only the node itself (and its attributes if the node is an XmlElement).

반환

복제된 노드입니다.The cloned node.

예제

다음 예제에서는 새 요소를 만듭니다, 그리고 복제 및 다음 XML 문서에 두 요소를 추가 합니다.The following example creates a new element, clones it, and then adds both elements into an XML document.

#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   XmlDocument^ doc = gcnew XmlDocument;
   doc->Load( "2books.xml" );
   
   // Create a new element.
   XmlElement^ elem = doc->CreateElement( "misc" );
   elem->InnerText = "hardcover";
   elem->SetAttribute( "publisher", "WorldWide Publishing" );
   
   // Clone the element so we can add one to each of the book nodes.
   XmlNode^ elem2 = elem->CloneNode( true );
   
   // Add the new elements.
   doc->DocumentElement->FirstChild->AppendChild( elem );
   doc->DocumentElement->LastChild->AppendChild( elem2 );
   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.Load("2books.xml");

    // Create a new element.
    XmlElement elem = doc.CreateElement("misc");
    elem.InnerText = "hardcover";
    elem.SetAttribute("publisher", "WorldWide Publishing");

    // Clone the element so we can add one to each of the book nodes.
    XmlNode elem2 = elem.CloneNode(true);

    // Add the new elements.
    doc.DocumentElement.FirstChild.AppendChild(elem);
    doc.DocumentElement.LastChild.AppendChild(elem2);

    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.Load("2books.xml")
        
        ' Create a new element.
        Dim elem As XmlElement = doc.CreateElement("misc")
        elem.InnerText = "hardcover"
        elem.SetAttribute("publisher", "WorldWide Publishing")
        
        ' Clone the element so we can add one to each of the book nodes.
        Dim elem2 As XmlNode = elem.CloneNode(True)
        
        ' Add the new elements.
        doc.DocumentElement.FirstChild.AppendChild(elem)
        doc.DocumentElement.LastChild.AppendChild(elem2)
        
        Console.WriteLine("Display the modified XML...")
        doc.Save(Console.Out)
    End Sub
End Class 'Sample

설명

이 메서드는 노드에 대 한 복사 생성자로 사용 됩니다.This method serves as a copy constructor for nodes. 중복 노드는 부모가 (ParentNode 반환 null).The duplicate node has no parent (ParentNode returns null).

적용 대상