DataTable.WriteXmlSchema Método

Definição

Grava a estrutura de dados atual do DataTable como um esquema XML.Writes the current data structure of the DataTable as an XML schema.

Sobrecargas

WriteXmlSchema(Stream)

Grava a estrutura de dados atual do DataTable como um esquema XML para o fluxo especificado.Writes the current data structure of the DataTable as an XML schema to the specified stream.

WriteXmlSchema(TextWriter)

Grava a estrutura de dados atual do DataTable como um esquema XML usando o TextWriter especificado.Writes the current data structure of the DataTable as an XML schema using the specified TextWriter.

WriteXmlSchema(String)

Grava a estrutura de dados atual do DataTable como um esquema XML para o arquivo especificado.Writes the current data structure of the DataTable as an XML schema to the specified file.

WriteXmlSchema(XmlWriter)

Grava a estrutura de dados atual do DataTable como um esquema XML usando o XmlWriter especificado.Writes the current data structure of the DataTable as an XML schema using the specified XmlWriter.

WriteXmlSchema(Stream, Boolean)

Grava a estrutura de dados atual do DataTable como um esquema XML para o fluxo especificado.Writes the current data structure of the DataTable as an XML schema to the specified stream. Para salvar o esquema da tabela e todos os descendentes, defina o parâmetro writeHierarchy como true.To save the schema for the table and all its descendants, set the writeHierarchy parameter to true.

WriteXmlSchema(TextWriter, Boolean)

Grava a estrutura de dados atual do DataTable como um esquema XML usando o TextWriter especificado.Writes the current data structure of the DataTable as an XML schema using the specified TextWriter. Para salvar o esquema da tabela e todos os descendentes, defina o parâmetro writeHierarchy como true.To save the schema for the table and all its descendants, set the writeHierarchy parameter to true.

WriteXmlSchema(XmlWriter, Boolean)

Grava a estrutura de dados atual do DataTable como um esquema XML usando o XmlWriter especificado.Writes the current data structure of the DataTable as an XML schema using the specified XmlWriter. Para salvar o esquema da tabela e todos os descendentes, defina o parâmetro writeHierarchy como true.To save the schema for the table and all its descendants, set the writeHierarchy parameter to true.

WriteXmlSchema(String, Boolean)

Grava a estrutura de dados atual do DataTable como um esquema XML para o arquivo especificado.Writes the current data structure of the DataTable as an XML schema to the specified file. Para salvar o esquema da tabela e todos os descendentes, defina o parâmetro writeHierarchy como true.To save the schema for the table and all its descendants, set the writeHierarchy parameter to true.

Exemplos

O aplicativo de console a seguir cria duas DataTable instâncias, adiciona cada uma a uma DataSet , cria uma DataRelation relacionando as duas tabelas e, em seguida, usa o WriteXmlSchema método para gravar os dados contidos na tabela pai em um TextWriter .The following console application creates two DataTable instances, adds each to a DataSet, creates a DataRelation relating the two tables, and then uses the WriteXmlSchema method to write the data contained within the parent table to a TextWriter. O exemplo demonstra o comportamento durante a definição do parâmetro writeHierarchy como cada um de seus valores.The example demonstrates the behavior when setting the writeHierarchy parameter to each of its values.

Observação

Este exemplo mostra como usar uma das versões sobrecarregadas do WriteXmlSchema para outros exemplos que podem estar disponíveis, consulte os tópicos de sobrecarga individuais.This example shows how to use one of the overloaded versions of WriteXmlSchema For other examples that might be available, see the individual overload topics.

static void Main()
{
    DataSet ds = new DataSet();
    DataTable customerTable = GetCustomers();
    DataTable orderTable = GetOrders();

    ds.Tables.Add(customerTable);
    ds.Tables.Add(orderTable);
    ds.Relations.Add("CustomerOrder",
        new DataColumn[] { customerTable.Columns[0] },
        new DataColumn[] { orderTable.Columns[1] }, true);

    System.IO.StringWriter writer = new System.IO.StringWriter();
    customerTable.WriteXmlSchema(writer, false);
    PrintOutput(writer, "Customer table, without hierarchy");

    writer = new System.IO.StringWriter();
    customerTable.WriteXmlSchema(writer, true);
    PrintOutput(writer, "Customer table, with hierarchy");

    Console.WriteLine("Press any key to continue.");
    Console.ReadKey();
}

private static DataTable GetCustomers()
{
    // Create sample Customers table, in order
    // to demonstrate the behavior of the DataTableReader.
    DataTable table = new DataTable();

    // Create two columns, ID and Name.
    DataColumn idColumn = table.Columns.Add("ID", typeof(System.Int32));
    table.Columns.Add("Name", typeof(System.String));

    // Set the ID column as the primary key column.
    table.PrimaryKey = new DataColumn[] { idColumn };

    table.Rows.Add(new object[] { 1, "Mary" });
    table.Rows.Add(new object[] { 2, "Andy" });
    table.Rows.Add(new object[] { 3, "Peter" });
    table.Rows.Add(new object[] { 4, "Russ" });
    table.AcceptChanges();
    return table;
}

private static DataTable GetOrders()
{
    // Create sample Customers table, in order
    // to demonstrate the behavior of the DataTableReader.
    DataTable table = new DataTable();

    // Create three columns; OrderID, CustomerID, and OrderDate.
    table.Columns.Add(new DataColumn("OrderID", typeof(System.Int32)));
    table.Columns.Add(new DataColumn("CustomerID", typeof(System.Int32)));
    table.Columns.Add(new DataColumn("OrderDate", typeof(System.DateTime)));

    // Set the OrderID column as the primary key column.
    table.PrimaryKey = new DataColumn[] { table.Columns[0] };

    table.Rows.Add(new object[] { 1, 1, "12/2/2003" });
    table.Rows.Add(new object[] { 2, 1, "1/3/2004" });
    table.Rows.Add(new object[] { 3, 2, "11/13/2004" });
    table.Rows.Add(new object[] { 4, 3, "5/16/2004" });
    table.Rows.Add(new object[] { 5, 3, "5/22/2004" });
    table.Rows.Add(new object[] { 6, 4, "6/15/2004" });
    table.AcceptChanges();
    return table;
}

private static void PrintOutput(System.IO.TextWriter writer,
    string caption)
{
    Console.WriteLine("==============================");
    Console.WriteLine(caption);
    Console.WriteLine("==============================");
    Console.WriteLine(writer.ToString());
}
Sub Main()
  Dim ds As New DataSet
  Dim customerTable As DataTable = GetCustomers()
  Dim orderTable As DataTable = GetOrders()

  ds.Tables.Add(customerTable)
  ds.Tables.Add(orderTable)
  ds.Relations.Add("CustomerOrder", _
   New DataColumn() {customerTable.Columns(0)}, _
   New DataColumn() {orderTable.Columns(1)}, True)

  Dim writer As New System.IO.StringWriter
  customerTable.WriteXmlSchema(writer, False)
  PrintOutput(writer, "Customer table, without hierarchy")

  writer = New System.IO.StringWriter
  customerTable.WriteXmlSchema(writer, True)
  PrintOutput(writer, "Customer table, with hierarchy")

  Console.WriteLine("Press any key to continue.")
  Console.ReadKey()
End Sub

Private Function GetOrders() As DataTable
  ' Create sample Customers table, in order
  ' to demonstrate the behavior of the DataTableReader.
  Dim table As New DataTable

  ' Create three columns, OrderID, CustomerID, and OrderDate.
  table.Columns.Add(New DataColumn("OrderID", GetType(System.Int32)))
  table.Columns.Add(New DataColumn("CustomerID", GetType(System.Int32)))
  table.Columns.Add(New DataColumn("OrderDate", GetType(System.DateTime)))

  ' Set the OrderID column as the primary key column.
  table.PrimaryKey = New DataColumn() {table.Columns(0)}

  table.Rows.Add(New Object() {1, 1, #12/2/2003#})
  table.Rows.Add(New Object() {2, 1, #1/3/2004#})
  table.Rows.Add(New Object() {3, 2, #11/13/2004#})
  table.Rows.Add(New Object() {4, 3, #5/16/2004#})
  table.Rows.Add(New Object() {5, 3, #5/22/2004#})
  table.Rows.Add(New Object() {6, 4, #6/15/2004#})
  table.AcceptChanges()
  Return table
End Function

Private Function GetCustomers() As DataTable
  ' Create sample Customers table, in order
  ' to demonstrate the behavior of the DataTableReader.
  Dim table As New DataTable

  ' Create two columns, ID and Name.
  Dim idColumn As DataColumn = table.Columns.Add("ID", GetType(System.Int32))
  table.Columns.Add("Name", GetType(System.String))

  ' Set the ID column as the primary key column.
  table.PrimaryKey = New DataColumn() {idColumn}

  table.Rows.Add(New Object() {1, "Mary"})
  table.Rows.Add(New Object() {2, "Andy"})
  table.Rows.Add(New Object() {3, "Peter"})
  table.Rows.Add(New Object() {4, "Russ"})
  table.AcceptChanges()
  Return table
End Function

Private Sub PrintOutput( _
   ByVal writer As System.IO.TextWriter, ByVal caption As String)

  Console.WriteLine("==============================")
  Console.WriteLine(caption)
  Console.WriteLine("==============================")
  Console.WriteLine(writer.ToString())
End Sub

O exemplo exibe a seguinte saída na janela do console:The example displays the following output in the console window:

==============================  
Customer table, without hierarchy  
==============================  
<?xml version="1.0" encoding="utf-16"?>  
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema"  
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">  
  <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:MainDataTable="Ta  
ble1">  
    <xs:complexType>  
      <xs:choice minOccurs="0" maxOccurs="unbounded">  
        <xs:element name="Table1">  
          <xs:complexType>  
            <xs:sequence>  
              <xs:element name="ID" type="xs:int" />  
              <xs:element name="Name" type="xs:string" minOccurs="0" />  
            </xs:sequence>  
          </xs:complexType>  
        </xs:element>  
      </xs:choice>  
    </xs:complexType>  
    <xs:unique name="Constraint1" msdata:PrimaryKey="true">  
      <xs:selector xpath=".//Table1" />  
      <xs:field xpath="ID" />  
    </xs:unique>  
  </xs:element>  
</xs:schema>  
==============================  
Customer table, with hierarchy  
==============================  
<?xml version="1.0" encoding="utf-16"?>  
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema"  
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">  
  <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:MainDataTable="Table1">  
    <xs:complexType>  
      <xs:choice minOccurs="0" maxOccurs="unbounded">  
        <xs:element name="Table1">  
          <xs:complexType>  
            <xs:sequence>  
              <xs:element name="ID" type="xs:int" />  
              <xs:element name="Name" type="xs:string" minOccurs="0" />  
            </xs:sequence>  
          </xs:complexType>  
        </xs:element>  
        <xs:element name="Table2">  
          <xs:complexType>  
            <xs:sequence>  
              <xs:element name="OrderID" type="xs:int" />  
              <xs:element name="CustomerID" type="xs:int" minOccurs="0" />  
              <xs:element name="OrderDate" type="xs:dateTime" minOccurs="0" />  
            </xs:sequence>  
          </xs:complexType>  
        </xs:element>  
      </xs:choice>  
    </xs:complexType>  
    <xs:unique name="Constraint1" msdata:PrimaryKey="true">  
      <xs:selector xpath=".//Table1" />  
      <xs:field xpath="ID" />  
    </xs:unique>  
    <xs:unique name="Table2_Constraint1" msdata:ConstraintName="Constraint1" msdata:PrimaryKey="true">  
      <xs:selector xpath=".//Table2" />  
      <xs:field xpath="OrderID" />  
    </xs:unique>  
    <xs:keyref name="CustomerOrder" refer="Constraint1">  
      <xs:selector xpath=".//Table2" />  
      <xs:field xpath="CustomerID" />  
    </xs:keyref>  
  </xs:element>  
</xs:schema>  

Comentários

Use o método WriteXmlSchema para gravar o esquema de um DataTable em um documento XML.Use the WriteXmlSchema method to write the schema for a DataTable to an XML document. O esquema inclui tabela, relação e definições de restrição.The schema includes table, relation, and constraint definitions.

O esquema XML é gravado usando o padrão XSD.The XML schema is written using the XSD standard.

Para gravar os dados em um documento XML, use o método WriteXml.To write the data to an XML document, use the WriteXml method.

WriteXmlSchema(Stream)

Grava a estrutura de dados atual do DataTable como um esquema XML para o fluxo especificado.Writes the current data structure of the DataTable as an XML schema to the specified stream.

public:
 void WriteXmlSchema(System::IO::Stream ^ stream);
public void WriteXmlSchema (System.IO.Stream stream);
member this.WriteXmlSchema : System.IO.Stream -> unit
Public Sub WriteXmlSchema (stream As Stream)

Parâmetros

stream
Stream

O fluxo no qual o esquema XML será gravado.The stream to which the XML schema will be written.

Comentários

Use o método WriteXmlSchema para gravar o esquema de um DataTable em um documento XML.Use the WriteXmlSchema method to write the schema for a DataTable to an XML document. O esquema inclui tabela, relação e definições de restrição.The schema includes table, relation, and constraint definitions.

O esquema XML é gravado usando o padrão XSD.The XML schema is written using the XSD standard.

Para gravar os dados em um documento XML, use o método WriteXml.To write the data to an XML document, use the WriteXml method.

Confira também

Aplica-se a

WriteXmlSchema(TextWriter)

Grava a estrutura de dados atual do DataTable como um esquema XML usando o TextWriter especificado.Writes the current data structure of the DataTable as an XML schema using the specified TextWriter.

public:
 void WriteXmlSchema(System::IO::TextWriter ^ writer);
public void WriteXmlSchema (System.IO.TextWriter writer);
member this.WriteXmlSchema : System.IO.TextWriter -> unit
Public Sub WriteXmlSchema (writer As TextWriter)

Parâmetros

writer
TextWriter

O TextWriter com o qual gravar.The TextWriter with which to write.

Comentários

Use o método WriteXmlSchema para gravar o esquema de um DataTable em um documento XML.Use the WriteXmlSchema method to write the schema for a DataTable to an XML document. O esquema inclui tabela, relação e definições de restrição.The schema includes table, relation, and constraint definitions.

O esquema XML é gravado usando o padrão XSD.The XML schema is written using the XSD standard.

Para gravar os dados em um documento XML, use o método WriteXml.To write the data to an XML document, use the WriteXml method.

Confira também

Aplica-se a

WriteXmlSchema(String)

Grava a estrutura de dados atual do DataTable como um esquema XML para o arquivo especificado.Writes the current data structure of the DataTable as an XML schema to the specified file.

public:
 void WriteXmlSchema(System::String ^ fileName);
public void WriteXmlSchema (string fileName);
member this.WriteXmlSchema : string -> unit
Public Sub WriteXmlSchema (fileName As String)

Parâmetros

fileName
String

O nome do arquivo a ser usado.The name of the file to use.

Comentários

Use o método WriteXmlSchema para gravar o esquema de um DataTable em um documento XML.Use the WriteXmlSchema method to write the schema for a DataTable to an XML document. O esquema inclui tabela, relação e definições de restrição.The schema includes table, relation, and constraint definitions.

O esquema XML é gravado usando o padrão XSD.The XML schema is written using the XSD standard.

Para gravar os dados em um documento XML, use o método WriteXml.To write the data to an XML document, use the WriteXml method.

Confira também

Aplica-se a

WriteXmlSchema(XmlWriter)

Grava a estrutura de dados atual do DataTable como um esquema XML usando o XmlWriter especificado.Writes the current data structure of the DataTable as an XML schema using the specified XmlWriter.

public:
 void WriteXmlSchema(System::Xml::XmlWriter ^ writer);
public void WriteXmlSchema (System.Xml.XmlWriter writer);
member this.WriteXmlSchema : System.Xml.XmlWriter -> unit
Public Sub WriteXmlSchema (writer As XmlWriter)

Parâmetros

writer
XmlWriter

O XmlWriter a ser usado.The XmlWriter to use.

Comentários

Use o método WriteXmlSchema para gravar o esquema de um DataTable em um documento XML.Use the WriteXmlSchema method to write the schema for a DataTable to an XML document. O esquema inclui tabela, relação e definições de restrição.The schema includes table, relation, and constraint definitions.

O esquema XML é gravado usando o padrão XSD.The XML schema is written using the XSD standard.

Para gravar os dados em um documento XML, use o método WriteXml.To write the data to an XML document, use the WriteXml method.

Confira também

Aplica-se a

WriteXmlSchema(Stream, Boolean)

Grava a estrutura de dados atual do DataTable como um esquema XML para o fluxo especificado.Writes the current data structure of the DataTable as an XML schema to the specified stream. Para salvar o esquema da tabela e todos os descendentes, defina o parâmetro writeHierarchy como true.To save the schema for the table and all its descendants, set the writeHierarchy parameter to true.

public:
 void WriteXmlSchema(System::IO::Stream ^ stream, bool writeHierarchy);
public void WriteXmlSchema (System.IO.Stream stream, bool writeHierarchy);
member this.WriteXmlSchema : System.IO.Stream * bool -> unit
Public Sub WriteXmlSchema (stream As Stream, writeHierarchy As Boolean)

Parâmetros

stream
Stream

O fluxo no qual o esquema XML será gravado.The stream to which the XML schema will be written.

writeHierarchy
Boolean

Se for true, grave o esquema da tabela atual e todos os descendentes.If true, write the schema of the current table and all its descendants. Se false (o valor padrão), grave apenas o esquema da tabela atual.If false (the default value), write the schema for the current table only.

Comentários

Use o método WriteXmlSchema para gravar o esquema de um DataTable em um documento XML.Use the WriteXmlSchema method to write the schema for a DataTable to an XML document. O esquema inclui tabela, relação e definições de restrição.The schema includes table, relation, and constraint definitions.

O esquema XML é gravado usando o padrão XSD.The XML schema is written using the XSD standard.

Para gravar os dados em um documento XML, use o método WriteXml.To write the data to an XML document, use the WriteXml method.

Normalmente, o método WriteXmlSchema grava o esquema somente para a tabela atual.Normally the WriteXmlSchema method writes the schema only for the current table. Para gravar o esquema da tabela atual e o descendente inteiro, tabelas relacionadas, chame um método com o parâmetro writeHierarchy definido como true.To write the schema for the current table and its entire descendant, related tables, call the method with the writeHierarchy parameter set to true.

Confira também

Aplica-se a

WriteXmlSchema(TextWriter, Boolean)

Grava a estrutura de dados atual do DataTable como um esquema XML usando o TextWriter especificado.Writes the current data structure of the DataTable as an XML schema using the specified TextWriter. Para salvar o esquema da tabela e todos os descendentes, defina o parâmetro writeHierarchy como true.To save the schema for the table and all its descendants, set the writeHierarchy parameter to true.

public:
 void WriteXmlSchema(System::IO::TextWriter ^ writer, bool writeHierarchy);
public void WriteXmlSchema (System.IO.TextWriter writer, bool writeHierarchy);
member this.WriteXmlSchema : System.IO.TextWriter * bool -> unit
Public Sub WriteXmlSchema (writer As TextWriter, writeHierarchy As Boolean)

Parâmetros

writer
TextWriter

O TextWriter com o qual gravar.The TextWriter with which to write.

writeHierarchy
Boolean

Se for true, grave o esquema da tabela atual e todos os descendentes.If true, write the schema of the current table and all its descendants. Se false (o valor padrão), grave apenas o esquema da tabela atual.If false (the default value), write the schema for the current table only.

Exemplos

O aplicativo de console a seguir cria duas DataTable instâncias, adiciona cada uma a uma DataSet , cria uma DataRelation relacionando as duas tabelas e, em seguida, usa o WriteXmlSchema método para gravar os dados contidos na tabela pai em um TextWriter .The following console application creates two DataTable instances, adds each to a DataSet, creates a DataRelation relating the two tables, and then uses the WriteXmlSchema method to write the data contained within the parent table to a TextWriter. O exemplo demonstra o comportamento durante a definição do parâmetro writeHierarchy como cada um de seus valores.The example demonstrates the behavior when setting the writeHierarchy parameter to each of its values.

static void Main()
{
    DataSet ds = new DataSet();
    DataTable customerTable = GetCustomers();
    DataTable orderTable = GetOrders();

    ds.Tables.Add(customerTable);
    ds.Tables.Add(orderTable);
    ds.Relations.Add("CustomerOrder",
        new DataColumn[] { customerTable.Columns[0] },
        new DataColumn[] { orderTable.Columns[1] }, true);

    System.IO.StringWriter writer = new System.IO.StringWriter();
    customerTable.WriteXmlSchema(writer, false);
    PrintOutput(writer, "Customer table, without hierarchy");

    writer = new System.IO.StringWriter();
    customerTable.WriteXmlSchema(writer, true);
    PrintOutput(writer, "Customer table, with hierarchy");

    Console.WriteLine("Press any key to continue.");
    Console.ReadKey();
}

private static DataTable GetCustomers()
{
    // Create sample Customers table, in order
    // to demonstrate the behavior of the DataTableReader.
    DataTable table = new DataTable();

    // Create two columns, ID and Name.
    DataColumn idColumn = table.Columns.Add("ID", typeof(System.Int32));
    table.Columns.Add("Name", typeof(System.String));

    // Set the ID column as the primary key column.
    table.PrimaryKey = new DataColumn[] { idColumn };

    table.Rows.Add(new object[] { 1, "Mary" });
    table.Rows.Add(new object[] { 2, "Andy" });
    table.Rows.Add(new object[] { 3, "Peter" });
    table.Rows.Add(new object[] { 4, "Russ" });
    table.AcceptChanges();
    return table;
}

private static DataTable GetOrders()
{
    // Create sample Customers table, in order
    // to demonstrate the behavior of the DataTableReader.
    DataTable table = new DataTable();

    // Create three columns; OrderID, CustomerID, and OrderDate.
    table.Columns.Add(new DataColumn("OrderID", typeof(System.Int32)));
    table.Columns.Add(new DataColumn("CustomerID", typeof(System.Int32)));
    table.Columns.Add(new DataColumn("OrderDate", typeof(System.DateTime)));

    // Set the OrderID column as the primary key column.
    table.PrimaryKey = new DataColumn[] { table.Columns[0] };

    table.Rows.Add(new object[] { 1, 1, "12/2/2003" });
    table.Rows.Add(new object[] { 2, 1, "1/3/2004" });
    table.Rows.Add(new object[] { 3, 2, "11/13/2004" });
    table.Rows.Add(new object[] { 4, 3, "5/16/2004" });
    table.Rows.Add(new object[] { 5, 3, "5/22/2004" });
    table.Rows.Add(new object[] { 6, 4, "6/15/2004" });
    table.AcceptChanges();
    return table;
}

private static void PrintOutput(System.IO.TextWriter writer, string caption)
{
    Console.WriteLine("==============================");
    Console.WriteLine(caption);
    Console.WriteLine("==============================");
    Console.WriteLine(writer.ToString());
}
Sub Main()
  Dim ds As New DataSet
  Dim customerTable As DataTable = GetCustomers()
  Dim orderTable As DataTable = GetOrders()

  ds.Tables.Add(customerTable)
  ds.Tables.Add(orderTable)
  ds.Relations.Add("CustomerOrder", _
   New DataColumn() {customerTable.Columns(0)}, _
   New DataColumn() {orderTable.Columns(1)}, True)

  Dim writer As New System.IO.StringWriter
  customerTable.WriteXmlSchema(writer, False)
  PrintOutput(writer, "Customer table, without hierarchy")

  writer = New System.IO.StringWriter
  customerTable.WriteXmlSchema(writer, True)
  PrintOutput(writer, "Customer table, with hierarchy")

  Console.WriteLine("Press any key to continue.")
  Console.ReadKey()
End Sub

Private Function GetOrders() As DataTable
  ' Create sample Customers table, in order
  ' to demonstrate the behavior of the DataTableReader.
  Dim table As New DataTable

  ' Create three columns, OrderID, CustomerID, and OrderDate.
  table.Columns.Add(New DataColumn("OrderID", GetType(System.Int32)))
  table.Columns.Add(New DataColumn("CustomerID", GetType(System.Int32)))
  table.Columns.Add(New DataColumn("OrderDate", GetType(System.DateTime)))

  ' Set the OrderID column as the primary key column.
  table.PrimaryKey = New DataColumn() {table.Columns(0)}

  table.Rows.Add(New Object() {1, 1, #12/2/2003#})
  table.Rows.Add(New Object() {2, 1, #1/3/2004#})
  table.Rows.Add(New Object() {3, 2, #11/13/2004#})
  table.Rows.Add(New Object() {4, 3, #5/16/2004#})
  table.Rows.Add(New Object() {5, 3, #5/22/2004#})
  table.Rows.Add(New Object() {6, 4, #6/15/2004#})
  table.AcceptChanges()
  Return table
End Function

Private Function GetCustomers() As DataTable
  ' Create sample Customers table, in order
  ' to demonstrate the behavior of the DataTableReader.
  Dim table As New DataTable

  ' Create two columns, ID and Name.
  Dim idColumn As DataColumn = table.Columns.Add("ID", _
      GetType(System.Int32))
  table.Columns.Add("Name", GetType(System.String))

  ' Set the ID column as the primary key column.
  table.PrimaryKey = New DataColumn() {idColumn}

  table.Rows.Add(New Object() {1, "Mary"})
  table.Rows.Add(New Object() {2, "Andy"})
  table.Rows.Add(New Object() {3, "Peter"})
  table.Rows.Add(New Object() {4, "Russ"})
  table.AcceptChanges()
  Return table
End Function

Private Sub PrintOutput( _
   ByVal writer As System.IO.TextWriter, ByVal caption As String)

  Console.WriteLine("==============================")
  Console.WriteLine(caption)
  Console.WriteLine("==============================")
  Console.WriteLine(writer.ToString())
End Sub

O exemplo exibe a seguinte saída na janela do console:The example displays the following output in the console window:

==============================  
Customer table, without hierarchy  
==============================  
<?xml version="1.0" encoding="utf-16"?>  
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema"  
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">  
  <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:MainDataTable="Ta  
ble1">  
    <xs:complexType>  
      <xs:choice minOccurs="0" maxOccurs="unbounded">  
        <xs:element name="Table1">  
          <xs:complexType>  
            <xs:sequence>  
              <xs:element name="ID" type="xs:int" />  
              <xs:element name="Name" type="xs:string" minOccurs="0" />  
            </xs:sequence>  
          </xs:complexType>  
        </xs:element>  
      </xs:choice>  
    </xs:complexType>  
    <xs:unique name="Constraint1" msdata:PrimaryKey="true">  
      <xs:selector xpath=".//Table1" />  
      <xs:field xpath="ID" />  
    </xs:unique>  
  </xs:element>  
</xs:schema>  
==============================  
Customer table, with hierarchy  
==============================  
<?xml version="1.0" encoding="utf-16"?>  
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema"  
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">  
  <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:MainDataTable="Table1">  
    <xs:complexType>  
      <xs:choice minOccurs="0" maxOccurs="unbounded">  
        <xs:element name="Table1">  
          <xs:complexType>  
            <xs:sequence>  
              <xs:element name="ID" type="xs:int" />  
              <xs:element name="Name" type="xs:string" minOccurs="0" />  
            </xs:sequence>  
          </xs:complexType>  
        </xs:element>  
        <xs:element name="Table2">  
          <xs:complexType>  
            <xs:sequence>  
              <xs:element name="OrderID" type="xs:int" />  
              <xs:element name="CustomerID" type="xs:int" minOccurs="0" />  
              <xs:element name="OrderDate" type="xs:dateTime" minOccurs="0" />  
            </xs:sequence>  
          </xs:complexType>  
        </xs:element>  
      </xs:choice>  
    </xs:complexType>  
    <xs:unique name="Constraint1" msdata:PrimaryKey="true">  
      <xs:selector xpath=".//Table1" />  
      <xs:field xpath="ID" />  
    </xs:unique>  
    <xs:unique name="Table2_Constraint1" msdata:ConstraintName="Constraint1" msdata:PrimaryKey="true">  
      <xs:selector xpath=".//Table2" />  
      <xs:field xpath="OrderID" />  
    </xs:unique>  
    <xs:keyref name="CustomerOrder" refer="Constraint1">  
      <xs:selector xpath=".//Table2" />  
      <xs:field xpath="CustomerID" />  
    </xs:keyref>  
  </xs:element>  
</xs:schema>  

Comentários

Use o método WriteXmlSchema para gravar o esquema de um DataTable em um documento XML.Use the WriteXmlSchema method to write the schema for a DataTable to an XML document. O esquema inclui tabela, relação e definições de restrição.The schema includes table, relation, and constraint definitions.

O esquema XML é gravado usando o padrão XSD.The XML schema is written using the XSD standard.

Para gravar os dados em um documento XML, use o método WriteXml.To write the data to an XML document, use the WriteXml method.

Normalmente, o método WriteXmlSchema grava o esquema somente para a tabela atual.Normally the WriteXmlSchema method writes the schema only for the current table. Para gravar o esquema da tabela atual e o descendente inteiro, tabelas relacionadas, chame um método com o parâmetro writeHierarchy definido como true.To write the schema for the current table and its entire descendant, related tables, call the method with the writeHierarchy parameter set to true.

Confira também

Aplica-se a

WriteXmlSchema(XmlWriter, Boolean)

Grava a estrutura de dados atual do DataTable como um esquema XML usando o XmlWriter especificado.Writes the current data structure of the DataTable as an XML schema using the specified XmlWriter. Para salvar o esquema da tabela e todos os descendentes, defina o parâmetro writeHierarchy como true.To save the schema for the table and all its descendants, set the writeHierarchy parameter to true.

public:
 void WriteXmlSchema(System::Xml::XmlWriter ^ writer, bool writeHierarchy);
public void WriteXmlSchema (System.Xml.XmlWriter writer, bool writeHierarchy);
member this.WriteXmlSchema : System.Xml.XmlWriter * bool -> unit
Public Sub WriteXmlSchema (writer As XmlWriter, writeHierarchy As Boolean)

Parâmetros

writer
XmlWriter

O XmlWriter usado para gravar o documento.The XmlWriter used to write the document.

writeHierarchy
Boolean

Se for true, grave o esquema da tabela atual e todos os descendentes.If true, write the schema of the current table and all its descendants. Se false (o valor padrão), grave apenas o esquema da tabela atual.If false (the default value), write the schema for the current table only.

Comentários

Use o método WriteXmlSchema para gravar o esquema de um DataTable em um documento XML.Use the WriteXmlSchema method to write the schema for a DataTable to an XML document. O esquema inclui tabela, relação e definições de restrição.The schema includes table, relation, and constraint definitions.

O esquema XML é gravado usando o padrão XSD.The XML schema is written using the XSD standard.

Para gravar os dados em um documento XML, use o método WriteXml.To write the data to an XML document, use the WriteXml method.

Normalmente, o método WriteXmlSchema grava o esquema somente para a tabela atual.Normally the WriteXmlSchema method writes the schema only for the current table. Para gravar o esquema da tabela atual e o descendente inteiro, tabelas relacionadas, chame um método com o parâmetro writeHierarchy definido como true.To write the schema for the current table and its entire descendant, related tables, call the method with the writeHierarchy parameter set to true.

Confira também

Aplica-se a

WriteXmlSchema(String, Boolean)

Grava a estrutura de dados atual do DataTable como um esquema XML para o arquivo especificado.Writes the current data structure of the DataTable as an XML schema to the specified file. Para salvar o esquema da tabela e todos os descendentes, defina o parâmetro writeHierarchy como true.To save the schema for the table and all its descendants, set the writeHierarchy parameter to true.

public:
 void WriteXmlSchema(System::String ^ fileName, bool writeHierarchy);
public void WriteXmlSchema (string fileName, bool writeHierarchy);
member this.WriteXmlSchema : string * bool -> unit
Public Sub WriteXmlSchema (fileName As String, writeHierarchy As Boolean)

Parâmetros

fileName
String

O nome do arquivo a ser usado.The name of the file to use.

writeHierarchy
Boolean

Se for true, grave o esquema da tabela atual e todos os descendentes.If true, write the schema of the current table and all its descendants. Se false (o valor padrão), grave apenas o esquema da tabela atual.If false (the default value), write the schema for the current table only.

Comentários

Use o método WriteXmlSchema para gravar o esquema de um DataTable em um documento XML.Use the WriteXmlSchema method to write the schema for a DataTable to an XML document. O esquema inclui tabela, relação e definições de restrição.The schema includes table, relation, and constraint definitions.

O esquema XML é gravado usando o padrão XSD.The XML schema is written using the XSD standard.

Para gravar os dados em um documento XML, use o método WriteXml.To write the data to an XML document, use the WriteXml method.

Normalmente, o método WriteXmlSchema grava o esquema somente para a tabela atual.Normally the WriteXmlSchema method writes the schema only for the current table. Para gravar o esquema da tabela atual e o descendente inteiro, tabelas relacionadas, chame um método com o parâmetro writeHierarchy definido como true.To write the schema for the current table and its entire descendant, related tables, call the method with the writeHierarchy parameter set to true.

Confira também

Aplica-se a