System.Xml.XmlDataDocument.CloneNode 方法

方法描述

创建当前节点的副本。

语法定义(C# System.Xml.XmlDataDocument.CloneNode 方法 的用法)

public override XmlNode CloneNode(
	bool deep
)

参数/返回值

参数值/返回值 参数类型/返回类型 参数描述/返回描述
deep System-Boolean 如果为 true,则递归地克隆指定节点下的子树;如果为 false,则只克隆该节点本身。
返回值 System.Xml.XmlNode 克隆的节点。

提示和注释

克隆 XmlDataDocument 的同时也克隆了 DataSet 架构。

如果 deep 设置为 false,则克隆的 DataSet 没有数据,即没有行。

如果 deep 设置为 true,则使用架构来设置克隆的 DataSet 并用数据对其进行填充。

请参见 XmlNode 类中的 CloneNode,以查看描述该方法操作每个不同节点类型的方式的表。

System.Xml.XmlDataDocument.CloneNode 方法例子

此示例使用 SQL Server 2000 Northwind 数据库。

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

异常

异常 异常描述

命名空间

namespace: System.Xml

程序集: System.Data(在 System.Data.dll 中)

版本信息

.NET Framework 受以下版本支持:4、3.5、3.0、2.0、1.1、1.0 .NET Framework Client Profile 受以下版本支持:4、3.5 SP1

适用平台

Windows 7, Windows Vista SP1 或更高版本, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008(不支持服务器核心), Windows Server 2008 R2(支持 SP1 或更高版本的服务器核心), Windows Server 2003 SP2 .NET Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求。