XmlDataDocument.CloneNode(Boolean) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
创建当前节点的副本。
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
。
返回
克隆的节点。
示例
以下示例将一个 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 架构。
如果 deep
设置为 false
,则克隆 DataSet
没有数据;也就是说,没有行。
如果 deep
设置为 true
,则使用架构设置克隆 DataSet
,然后使用数据填充。
请参阅 CloneNode 类中的 XmlNode
一个表,其中介绍了此方法与每个不同节点类型的行为方式。