XmlDataDocument::CloneNode Method

Creates a duplicate of the current node.

Namespace:  System.Xml
Assembly:  System.Data (in System.Data.dll)

public:
virtual XmlNode^ CloneNode(
	bool deep
) override

Parameters

deep
Type: System::Boolean

true to recursively clone the subtree under the specified node; false to clone only the node itself.

Return Value

Type: System.Xml::XmlNode
The cloned node.

Cloning the XmlDataDocument also clones the DataSet schema.

If deep is set to false, the cloned DataSet has no data; that is, no rows.

If deep is set to true, the cloned DataSet is set with the schema and then populated with the data.

See CloneNode in the XmlNode class to see a table describing how this method behaves with each of the different node types.

The following example loads a DataSet into an XmlDataDocument and then creates a shallow clone of the XmlDataDocument.

The example uses the SQL Server 2000 Northwind database.

#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() );
}

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft