XmlDataDocument.CloneNode Method (Boolean)

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Creates a duplicate of the current node.

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

Public Overrides Function CloneNode (
	deep As Boolean
) As XmlNode

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.


Imports System
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

.NET Framework
Available since 1.1
Return to top
Show: