다음을 통해 공유


XmlDataDocument.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

복제된 노드입니다.

예제

다음 예제에서는 a를 DataSet XmlDataDocument 로드한 다음 단순 복제본을 XmlDataDocument만듭니다.

이 예제에서는 SQL Server 2000 Northwind 데이터베이스를 사용합니다.

#using <System.Xml.dll>
#using <System.Transactions.dll>
#using <System.EnterpriseServices.dll>
#using <System.dll>
#using <System.Data.dll>

using namespace System;
using namespace System::Data;
using namespace System::Xml;
using namespace System::Data::SqlClient;
int main()
{
   DataSet^ dsNorthwind = gcnew DataSet;
   
   //Create the connection string.           
   String^ sConnect;
   sConnect = "Data Source=localhost;Integrated Security=SSPI;Initial Catalog=Northwind";
   
   //Create a connection object to connect to the northwind db.
   SqlConnection^ nwconnect = gcnew SqlConnection( sConnect );
   
   //Create a command string to select all the customers in the WA region.
   String^ sCommand = "Select * from Customers where Region='WA'";
   
   //Create an adapter to load the DataSet.
   SqlDataAdapter^ myDataAdapter = gcnew SqlDataAdapter( sCommand,nwconnect );
   
   //Fill the DataSet with the selected records.
   myDataAdapter->Fill( dsNorthwind, "Customers" );
   
   //Load the document with the DataSet.
   XmlDataDocument^ doc = gcnew XmlDataDocument( dsNorthwind );
   
   //Create a shallow clone of the XmlDataDocument. Note that although
   //none of the child nodes were copied over, the cloned node does
   //have the schema information.
   XmlDataDocument^ clone = dynamic_cast<XmlDataDocument^>(doc->CloneNode( false ));
   Console::WriteLine( "Child count: {0}", clone->ChildNodes->Count );
   Console::WriteLine( clone->DataSet->GetXmlSchema() );
}

using System;
using System.Data;
using System.Xml;
using System.Data.SqlClient;

public class Sample
{
  public static void Main()
  {
     DataSet dsNorthwind = new DataSet();

     //Create the connection string.
     String sConnect;
     sConnect="Data Source=localhost;Integrated Security=SSPI;Initial Catalog=Northwind";

     //Create a connection object to connect to the northwind db.
     SqlConnection nwconnect = new SqlConnection(sConnect);

     //Create a command string to select all the customers in the WA region.
     String sCommand = "Select * from Customers where Region='WA'";

     //Create an adapter to load the DataSet.
     SqlDataAdapter myDataAdapter = new SqlDataAdapter(sCommand, nwconnect);

     //Fill the DataSet with the selected records.
     myDataAdapter.Fill(dsNorthwind,"Customers");

     //Load the document with the DataSet.
     XmlDataDocument doc = new XmlDataDocument(dsNorthwind);

     //Create a shallow clone of the XmlDataDocument. Note that although
     //none of the child nodes were copied over, the cloned node does
     //have the schema information.
     XmlDataDocument clone = (XmlDataDocument) doc.CloneNode(false);
     Console.WriteLine("Child count: {0}", clone.ChildNodes.Count);
     Console.WriteLine(clone.DataSet.GetXmlSchema());
  }
}

Imports System.Xml
Imports System.Data
Imports System.Data.SqlClient

public class Sample
 
  public shared sub Main()
   
    Dim dsNorthwind as DataSet = new DataSet()
 
    'Create the connection string.
    Dim sConnect as String           
    sConnect="Data Source=localhost;Integrated Security=SSPI;Initial Catalog=Northwind"     
          
    'Create a connection object to connect to the northwind db.
    Dim nwconnect as SqlConnection
    nwconnect = new SqlConnection(sConnect)
 
    'Create a command string to select all the customers in the WA region.
    Dim sCommand as String = "Select * from Customers where Region='WA'"
 
    'Create an Adapter to load the DataSet.
    Dim myDataAdapter as SqlDataAdapter
    myDataAdapter = new SqlDataAdapter(sCommand, nwconnect)
 
    'Fill the DataSet with the selected records.
    myDataAdapter.Fill(dsNorthwind, "Customers")
 
    'Load the document with the DataSet.
    Dim doc as XmlDataDocument = new XmlDataDocument(dsNorthwind)  
 
    'Create a shallow clone of the XmlDataDocument. Note that although
    'none of the child nodes were copied over, the cloned node does
    'have the schema information.
    Dim clone as XmlDataDocument
    clone = CType (doc.CloneNode(false), XmlDataDocument) 
    Console.WriteLine("Child count: {0}", clone.ChildNodes.Count)
    Console.WriteLine(clone.DataSet.GetXmlSchema())
 
  end sub
end class

설명

또한 복제는 XmlDataDocument 스키마를 복제합니다 DataSet .

설정된 false경우 deep 복제 DataSet 된 데이터에는 데이터가 없습니다. 즉, 행이 없습니다.

설정true되면 deep 복제 DataSet 된 데이터베이스가 스키마로 설정된 다음 데이터로 채워집니다.

클래스에서 이 메서드가 XmlNode 서로 다른 각 노드 형식에서 동작하는 방식을 설명하는 테이블을 참조 CloneNode 하세요.

적용 대상