現在のノードの複製を作成します。
Overrides Public Function CloneNode( _
ByVal deep As Boolean _) As XmlNode
[C#]
public override XmlNode CloneNode(booldeep);
[C++]
public: XmlNode* CloneNode(booldeep);
[JScript]
public override function CloneNode(
deep : Boolean) : XmlNode;
パラメータ
- deep
指定したノードの下にあるサブツリーのクローンを順次作成していく場合は true 。指定したノードだけのクローンを作成する場合は false 。
戻り値
クローンとして作成されたノード。
解説
XmlDataDocument のクローンを作成すると、 DataSet スキーマのクローンも作成されます。
deep を false に設定した場合は、クローンとして作成された DataSet にはデータがない、つまり行がありません。
deep を true に設定した場合は、クローンとして作成された DataSet はスキーマを使用して設定され、データが読み込まれます。
このメソッドが異なるノード型でどのように動作するかを説明した表を確認するには、 XmlNode クラスの CloneNode のトピックを参照してください。
使用例
[Visual Basic, C#, C++] DataSet を XmlDataDocument に読み込み、 XmlDataDocument の簡易クローンを作成する例を次に示します。
[Visual Basic, C#, C++] この例では、SQL Server 2000 Northwind データベースを使用しています。
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
[C#]
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());
}
}
[C++]
#using <mscorlib.dll>
#using <System.Xml.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 = new DataSet();
//Create the connection string.
String* sConnect;
sConnect=S"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 = S"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,S"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 = dynamic_cast<XmlDataDocument*> (doc->CloneNode(false));
Console::WriteLine(S"Child count: {0}", __box(clone->ChildNodes->Count));
Console::WriteLine(clone->DataSet->GetXmlSchema());
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ