XmlDocument.CloneNode(Boolean) 메서드

정의

이 노드의 복제본을 만듭니다.

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

지정된 노드 아래의 하위 트리를 재귀적으로 복제하려면 true이고, 노드 자체만 복제하려면 false입니다.

반환

XmlNode

복제된 XmlDocument 노드입니다.

예제

다음 예제에서는 깊고 단순한 클론 간의 차이를 보여 있습니다.

#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   
   //Create the XmlDocument.
   XmlDocument^ doc = gcnew XmlDocument;
   doc->LoadXml( "<book genre='novel' ISBN='1-861001-57-5'><title>Pride And Prejudice</title></book>" );
   
   //Create a deep clone.  The cloned node 
   //includes the child node.
   XmlDocument^ deep = dynamic_cast<XmlDocument^>(doc->CloneNode( true ));
   Console::WriteLine( deep->ChildNodes->Count );
   
   //Create a shallow clone.  The cloned node does not 
   //include the child node.
   XmlDocument^ shallow = dynamic_cast<XmlDocument^>(doc->CloneNode( false ));
   Console::WriteLine( "{0}{1}", shallow->Name, shallow->OuterXml );
   Console::WriteLine( shallow->ChildNodes->Count );
}

using System;
using System.IO;
using System.Xml;

public class Sample
{
  public static void Main()
  {
    //Create the XmlDocument.
    XmlDocument doc = new XmlDocument();
    doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" +
                "<title>Pride And Prejudice</title>" +
                "</book>");

    //Create a deep clone.  The cloned node
    //includes the child node.
    XmlDocument deep = (XmlDocument) doc.CloneNode(true);
    Console.WriteLine(deep.ChildNodes.Count);

    //Create a shallow clone.  The cloned node does not
    //include the child node.
    XmlDocument shallow = (XmlDocument) doc.CloneNode(false);
    Console.WriteLine(shallow.Name + shallow.OuterXml);
    Console.WriteLine(shallow.ChildNodes.Count);
  }
}
Option Explicit
Option Strict

Imports System.IO
Imports System.Xml

Public Class Sample
    
    Public Shared Sub Main()
        'Create the XmlDocument.
        Dim doc As New XmlDocument()
        doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>"  & _
                    "<title>Pride And Prejudice</title>"  & _
                    "</book>")
        
        'Create a deep clone.  The cloned node 
        'includes the child node.
        Dim deep As XmlDocument = CType(doc.CloneNode(True), XmlDocument)
        Console.WriteLine(deep.ChildNodes.Count)
        
        'Create a shallow clone.  The cloned node does not 
        'include the child node.
        Dim shallow As XmlDocument = CType(doc.CloneNode(False), XmlDocument)
        Console.WriteLine(shallow.Name + shallow.OuterXml)
        Console.WriteLine(shallow.ChildNodes.Count)
    End Sub
End Class

설명

이 메서드는 노드에 대한 복사 생성자 역할을 합니다. 복제된 노드에는 부모(ParentNode 반환 null)가 없습니다.

true경우 deep 복제된 노드에는 모든 자식 노드가 포함되고, 그렇지 않으면 노드만 XmlDocument 복제됩니다. 이 메서드가 XmlNode.CloneNode 다른 노드 형식에서 어떻게 동작하는지 확인하려면 메서드를 참조하세요.

적용 대상