CloneNode Method

XmlDataDocument.CloneNode Method

Creates a duplicate of the current node.

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

public override XmlNode CloneNode (
	bool deep
)
public XmlNode CloneNode (
	boolean deep
)
public override function CloneNode (
	deep : boolean
) : XmlNode
Not applicable.

Parameters

deep

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

Return Value

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

import System.*;
import System.Data.*;
import System.Xml.*;
import System.Data.SqlClient.*;

public class Sample
{
    public static void main(String[] args)
    {
        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}", 
            System.Convert.ToString(clone.get_ChildNodes().get_Count()));
        Console.WriteLine(clone.get_DataSet().GetXmlSchema());
    } //main
} //Sample

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2016 Microsoft