XmlDataDocument.CloneNode(Boolean) Método
Definição
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
Cria uma duplicata do nó atual.
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
Parâmetros
- deep
- Boolean
true
para recursivamente clonar a subárvore abaixo do nó especificado; false
para clonar apenas o próprio nó.
Retornos
O nó clonado.
Exemplos
O exemplo a seguir carrega um DataSet
em um XmlDataDocument
e cria um clone superficial do XmlDataDocument
.
O exemplo usa o banco de dados northwind SQL Server 2000.
#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
Comentários
A clonagem XmlDataDocument
também clona o DataSet esquema.
Se deep
estiver definido como false
, o clonado DataSet
não tem dados; ou seja, nenhuma linha.
Se deep
estiver definido como true
, o clonado DataSet
será definido com o esquema e preenchido com os dados.
Consulte CloneNode na XmlNode
classe para ver uma tabela que descreve como esse método se comporta com cada um dos diferentes tipos de nó.