DataTable.ReadXmlSchema Método

Definição

Lê um esquema XML no DataTable.

Sobrecargas

Nome Description
ReadXmlSchema(XmlReader)

Lê um esquema XML no DataTable uso do .XmlReader

ReadXmlSchema(String)

Lê um esquema XML no DataTable arquivo especificado.

ReadXmlSchema(TextReader)

Lê um esquema XML no DataTable uso do .TextReader

ReadXmlSchema(Stream)

Lê um esquema XML no DataTable fluxo de uso especificado.

Comentários

Use o ReadXmlSchema método para criar o esquema para um DataTable. O esquema inclui definições de tabela, relação e restrição.

Para gravar um esquema em um documento XML, use o WriteXmlSchema método.

O esquema XML é interpretado de acordo com o padrão XSD.

O ReadXmlSchema método geralmente é invocado antes de invocar o ReadXml método usado para preencher o DataTable.

ReadXmlSchema(XmlReader)

Lê um esquema XML no DataTable uso do .XmlReader

public:
 void ReadXmlSchema(System::Xml::XmlReader ^ reader);
public void ReadXmlSchema(System.Xml.XmlReader reader);
member this.ReadXmlSchema : System.Xml.XmlReader -> unit
Public Sub ReadXmlSchema (reader As XmlReader)

Parâmetros

reader
XmlReader

O XmlReader usado para ler as informações do esquema.

Exemplos

O aplicativo de console a seguir cria um novo DataTablee grava o esquema dessa tabela em um MemoryStream. Em seguida, o exemplo cria um novo DataTable e lê seu esquema do esquema XML salvo, usando um XmlTextReader (que herda de XmlReader) como sua origem.

private static void DemonstrateReadWriteXMLSchemaWithReader()
{
    DataTable table = CreateTestTable("XmlDemo");
    PrintSchema(table, "Original table");

    // Write the schema to XML in a memory stream.
    System.IO.MemoryStream xmlStream =
        new System.IO.MemoryStream();
    table.WriteXmlSchema(xmlStream);

    // Rewind the memory stream.
    xmlStream.Position = 0;

    DataTable newTable = new DataTable();
    System.Xml.XmlTextReader reader =
        new System.Xml.XmlTextReader(xmlStream);
    newTable.ReadXmlSchema(reader);

    // Print out values in the table.
    PrintSchema(newTable, "New table");
}

private static DataTable CreateTestTable(string tableName)
{
    // Create a test DataTable with two columns and a few rows.
    DataTable table = new DataTable(tableName);
    DataColumn column = new DataColumn("id", typeof(System.Int32));
    column.AutoIncrement = true;
    table.Columns.Add(column);

    column = new DataColumn("item", typeof(System.String));
    table.Columns.Add(column);

    // Add ten rows.
    DataRow row;
    for (int i = 0; i <= 9; i++)
    {
        row = table.NewRow();
        row["item"] = "item " + i;
        table.Rows.Add(row);
    }

    table.AcceptChanges();
    return table;
}

private static void PrintSchema(DataTable table, string label)
{
    // Display the schema of the supplied DataTable:
    Console.WriteLine(label);
    foreach (DataColumn column in table.Columns)
    {
        Console.WriteLine("\t{0}: {1}", column.ColumnName,
            column.DataType.Name);
    }
    Console.WriteLine();
}
Private Sub DemonstrateReadWriteXMLSchemaWithReader()
  Dim table As DataTable = CreateTestTable("XmlDemo")
  PrintSchema(table, "Original table")

  ' Write the schema to XML in a memory stream.
  Dim xmlStream As New System.IO.MemoryStream()
  table.WriteXmlSchema(xmlStream)

  ' Rewind the memory stream.
  xmlStream.Position = 0

  Dim newTable As New DataTable
  Dim reader As New System.Xml.XmlTextReader(xmlStream)
  newTable.ReadXmlSchema(reader)

  ' Print out values in the table.
  PrintSchema(newTable, "New Table")
End Sub

Private Function CreateTestTable(ByVal tableName As String) _
      As DataTable
  ' Create a test DataTable with two columns and a few rows.
  Dim table As New DataTable(tableName)
  Dim column As New DataColumn("id", GetType(System.Int32))
  column.AutoIncrement = True
  table.Columns.Add(column)

  column = New DataColumn("item", GetType(System.String))
  table.Columns.Add(column)

  ' Add ten rows.
  Dim row As DataRow
  For i As Integer = 0 To 9
    row = table.NewRow()
    row("item") = "item " & i
    table.Rows.Add(row)
  Next i

  table.AcceptChanges()
  Return table
End Function

Private Sub PrintSchema(ByVal table As DataTable, _
      ByVal label As String)
  ' Display the schema of the supplied DataTable:
  Console.WriteLine(label)
  For Each column As DataColumn In table.Columns
    Console.WriteLine("{0}{1}: {2}", ControlChars.Tab, _
      column.ColumnName, column.DataType.Name)
  Next column
End Sub

Comentários

Use o ReadXmlSchema método para criar o esquema para um DataTable. O esquema inclui definições de tabela, relação e restrição.

Para gravar um esquema em um documento XML, use o WriteXmlSchema método.

O esquema XML é interpretado de acordo com o padrão XSD.

A corrupção de dados poderá ocorrer se os tipos msdata:DataType e xs:type não corresponderem. Nenhuma exceção será gerada.

O ReadXmlSchema método geralmente é invocado antes de invocar o ReadXml método usado para preencher o DataTable.

Note

A maneira de criar uma relação aninhada usando o esquema XML é ter elementos aninhados implícitos. Além disso, a relação aninhada pode ser redirecionada para usar nomes de coluna explícitos. É obrigatório que os elementos sejam implicitamente aninhados para que os DataTables correspondentes participem de uma relação aninhada.

Confira também

Aplica-se a

ReadXmlSchema(String)

Lê um esquema XML no DataTable arquivo especificado.

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

Parâmetros

fileName
String

O nome do arquivo do qual ler as informações do esquema.

Exemplos

O aplicativo de console a seguir cria um novo DataTablee grava o esquema dessa tabela em um arquivo. Em seguida, o exemplo cria um novo DataTable e lê seu esquema do esquema XML salvo, usando o arquivo como sua origem.

private static void DemonstrateReadWriteXMLSchemaWithFile()
{
    DataTable table = CreateTestTable("XmlDemo");
    PrintSchema(table, "Original table");

    // Write the schema to XML in a file.
    string xmlFile = "C:\\SchemaDemo.xml";
    table.WriteXmlSchema(xmlFile);

    DataTable newTable = new DataTable();
    newTable.ReadXmlSchema(xmlFile);

    // Print out values in the table.
    PrintSchema(newTable, "New table");
}

private static DataTable CreateTestTable(string tableName)
{
    // Create a test DataTable with two columns and a few rows.
    DataTable table = new DataTable(tableName);
    DataColumn column = new DataColumn("id", typeof(System.Int32));
    column.AutoIncrement = true;
    table.Columns.Add(column);

    column = new DataColumn("item", typeof(System.String));
    table.Columns.Add(column);

    // Add ten rows.
    DataRow row;
    for (int i = 0; i <= 9; i++)
    {
        row = table.NewRow();
        row["item"] = "item " + i;
        table.Rows.Add(row);
    }

    table.AcceptChanges();
    return table;
}

private static void PrintSchema(DataTable table, string label)
{
    // Display the schema of the supplied DataTable:
    Console.WriteLine(label);
    foreach (DataColumn column in table.Columns)
    {
        Console.WriteLine("\t{0}: {1}", column.ColumnName,
            column.DataType.Name);
    }
    Console.WriteLine();
}
Private Sub DemonstrateReadWriteXMLSchemaWithFile()
  Dim table As DataTable = CreateTestTable("XmlDemo")
  PrintSchema(table, "Original table")

  Dim xmlFile As String = "SchemaDemo.xml"

  ' Write the schema to XML.
  table.WriteXmlSchema(xmlFile)

  Dim newTable As New DataTable
  newTable.ReadXmlSchema(xmlFile)

  ' Print out values in the table.
  PrintSchema(newTable, "New Table")
End Sub

Private Function CreateTestTable(ByVal tableName As String) _
      As DataTable
  ' Create a test DataTable with two columns and a few rows.
  Dim table As New DataTable(tableName)
  Dim column As New DataColumn("id", GetType(System.Int32))
  column.AutoIncrement = True
  table.Columns.Add(column)

  column = New DataColumn("item", GetType(System.String))
  table.Columns.Add(column)

  ' Add ten rows.
  Dim row As DataRow
  For i As Integer = 0 To 9
    row = table.NewRow()
    row("item") = "item " & i
    table.Rows.Add(row)
  Next i

  table.AcceptChanges()
  Return table
End Function

Private Sub PrintSchema(ByVal table As DataTable, _
      ByVal label As String)
  ' Display the schema of the supplied DataTable:
  Console.WriteLine(label)
  For Each column As DataColumn In table.Columns
    Console.WriteLine("{0}{1}: {2}", ControlChars.Tab, _
      column.ColumnName, column.DataType.Name)
  Next column
End Sub

Comentários

Use o ReadXmlSchema método para criar o esquema para um DataTable. O esquema inclui definições de tabela, relação e restrição.

Para gravar um esquema em um documento XML, use o WriteXmlSchema método.

O esquema XML é interpretado de acordo com o padrão XSD.

A corrupção de dados poderá ocorrer se os tipos msdata:DataType e xs:type não corresponderem. Nenhuma exceção será gerada.

O ReadXmlSchema método geralmente é invocado antes de invocar o ReadXml método usado para preencher o DataTable.

Para criar uma relação aninhada usando o esquema XML, use elementos aninhados implícitos. Você também pode reconfigurar a relação aninhada para usar nomes de coluna explícitos. Os elementos devem ser implicitamente aninhados para que os DataTables correspondentes participem de uma relação aninhada.

Confira também

Aplica-se a

ReadXmlSchema(TextReader)

Lê um esquema XML no DataTable uso do .TextReader

public:
 void ReadXmlSchema(System::IO::TextReader ^ reader);
public void ReadXmlSchema(System.IO.TextReader reader);
member this.ReadXmlSchema : System.IO.TextReader -> unit
Public Sub ReadXmlSchema (reader As TextReader)

Parâmetros

reader
TextReader

O TextReader usado para ler as informações do esquema.

Exemplos

O aplicativo de console a seguir cria um novo DataTablee grava o esquema dessa tabela em um MemoryStream. Em seguida, o exemplo cria um novo DataTable e lê seu esquema do esquema XML salvo, usando um StreamReader (que herda de TextReader) como sua origem.

private static void DemonstrateReadWriteXMLSchemaWithReader()
{
    DataTable table = CreateTestTable("XmlDemo");
    PrintSchema(table, "Original table");

    // Write the schema to XML in a memory stream.
    System.IO.MemoryStream xmlStream = new System.IO.MemoryStream();
    table.WriteXmlSchema(xmlStream);

    // Rewind the memory stream.
    xmlStream.Position = 0;

    DataTable newTable = new DataTable();
    System.IO.StreamReader reader =
        new System.IO.StreamReader(xmlStream);
    newTable.ReadXmlSchema(reader);

    // Print out values in the table.
    PrintSchema(newTable, "New table");
}

private static DataTable CreateTestTable(string tableName)
{
    // Create a test DataTable with two columns and a few rows.
    DataTable table = new DataTable(tableName);
    DataColumn column = new DataColumn("id", typeof(System.Int32));
    column.AutoIncrement = true;
    table.Columns.Add(column);

    column = new DataColumn("item", typeof(System.String));
    table.Columns.Add(column);

    // Add ten rows.
    DataRow row;
    for (int i = 0; i <= 9; i++)
    {
        row = table.NewRow();
        row["item"] = "item " + i;
        table.Rows.Add(row);
    }

    table.AcceptChanges();
    return table;
}

private static void PrintSchema(DataTable table, string label)
{
    // Display the schema of the supplied DataTable:
    Console.WriteLine(label);
    foreach (DataColumn column in table.Columns)
    {
        Console.WriteLine("\t{0}: {1}",
            column.ColumnName, column.DataType.Name);
    }
    Console.WriteLine();
}
Private Sub DemonstrateReadWriteXMLSchemaWithReader()
  Dim table As DataTable = CreateTestTable("XmlDemo")
  PrintSchema(table, "Original table")

  ' Write the schema to XML in a memory stream.
  Dim xmlStream As New System.IO.MemoryStream()
  table.WriteXmlSchema(xmlStream)

  ' Rewind the memory stream.
  xmlStream.Position = 0

  Dim newTable As New DataTable
  Dim reader As New System.IO.StreamReader(xmlStream)
  newTable.ReadXmlSchema(reader)

  ' Print out values in the table.
  PrintSchema(newTable, "New Table")
End Sub

Private Function CreateTestTable(ByVal tableName As String) _
  As DataTable

  ' Create a test DataTable with two columns and a few rows.
  Dim table As New DataTable(tableName)
  Dim column As New DataColumn("id", GetType(System.Int32))
  column.AutoIncrement = True
  table.Columns.Add(column)

  column = New DataColumn("item", GetType(System.String))
  table.Columns.Add(column)

  ' Add ten rows.
  Dim row As DataRow
  For i As Integer = 0 To 9
    row = table.NewRow()
    row("item") = "item " & i
    table.Rows.Add(row)
  Next i

  table.AcceptChanges()
  Return table
End Function

Private Sub PrintSchema(ByVal table As DataTable, _
  ByVal label As String)

  ' Display the schema of the supplied DataTable:
  Console.WriteLine(label)
  For Each column As DataColumn In table.Columns
    Console.WriteLine("{0}{1}: {2}", ControlChars.Tab, _
      column.ColumnName, column.DataType.Name)
  Next column
End Sub

Comentários

Use o ReadXmlSchema método para criar o esquema para um DataTable. O esquema inclui definições de tabela, relação e restrição.

Para gravar um esquema em um documento XML, use o WriteXmlSchema método.

O esquema XML é interpretado de acordo com o padrão XSD.

A corrupção de dados poderá ocorrer se os tipos msdata:DataType e xs:type não corresponderem. Nenhuma exceção será gerada.

O ReadXmlSchema método geralmente é invocado antes de invocar o ReadXml método usado para preencher o DataTable.

Para criar uma relação aninhada usando o esquema XML, use elementos aninhados implícitos. Você também pode reconfigurar a relação aninhada para usar nomes de coluna explícitos. Os elementos devem ser implicitamente aninhados para que os DataTables correspondentes participem de uma relação aninhada.

Confira também

Aplica-se a

ReadXmlSchema(Stream)

Lê um esquema XML no DataTable fluxo de uso especificado.

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

Parâmetros

stream
Stream

O fluxo usado para ler o esquema.

Exemplos

O aplicativo de console a seguir cria um novo DataTablee grava o esquema dessa tabela em um MemoryStream. Em seguida, o exemplo cria um novo DataTable e lê seu esquema do esquema XML salvo.

private static void DemonstrateReadWriteXMLSchemaWithStream()
{
    DataTable table = CreateTestTable("XmlDemo");
    PrintSchema(table, "Original table");

    // Write the schema to XML in a memory stream.
    System.IO.MemoryStream xmlStream = new System.IO.MemoryStream();
    table.WriteXmlSchema(xmlStream);

    // Rewind the memory stream.
    xmlStream.Position = 0;

    DataTable newTable = new DataTable();
    newTable.ReadXmlSchema(xmlStream);

    // Print out values in the table.
    PrintSchema(newTable, "New table");
}

private static DataTable CreateTestTable(string tableName)
{
    // Create a test DataTable with two columns and a few rows.
    DataTable table = new DataTable(tableName);
    DataColumn column = new DataColumn("id", typeof(System.Int32));
    column.AutoIncrement = true;
    table.Columns.Add(column);

    column = new DataColumn("item", typeof(System.String));
    table.Columns.Add(column);

    // Add ten rows.
    DataRow row;
    for (int i = 0; i <= 9; i++)
    {
        row = table.NewRow();
        row["item"] = "item " + i;
        table.Rows.Add(row);
    }

    table.AcceptChanges();
    return table;
}

private static void PrintSchema(DataTable table, string label)
{
    // Display the schema of the supplied DataTable:
    Console.WriteLine(label);
    foreach (DataColumn column in table.Columns)
    {
        Console.WriteLine("\t{0}: {1}", column.ColumnName,
            column.DataType.Name);
    }
    Console.WriteLine();
}
Private Sub DemonstrateReadWriteXMLSchemaWithStream()
  Dim table As DataTable = CreateTestTable("XmlDemo")
  PrintSchema(table, "Original table")

  ' Write the schema to XML in a memory stream.
  Dim xmlStream As New System.IO.MemoryStream()
  table.WriteXmlSchema(xmlStream)

  ' Rewind the memory stream.
  xmlStream.Position = 0

  Dim newTable As New DataTable
  newTable.ReadXmlSchema(xmlStream)

  ' Print out values in the table.
  PrintSchema(newTable, "New Table")
End Sub

Private Function CreateTestTable(ByVal tableName As String) _
  As DataTable

  ' Create a test DataTable with two columns and a few rows.
  Dim table As New DataTable(tableName)
  Dim column As New DataColumn("id", GetType(System.Int32))
  column.AutoIncrement = True
  table.Columns.Add(column)

  column = New DataColumn("item", GetType(System.String))
  table.Columns.Add(column)

  ' Add ten rows.
  Dim row As DataRow
  For i As Integer = 0 To 9
    row = table.NewRow()
    row("item") = "item " & i
    table.Rows.Add(row)
  Next i

  table.AcceptChanges()
  Return table
End Function

Private Sub PrintSchema(ByVal table As DataTable, _
  ByVal label As String)

  ' Display the schema of the supplied DataTable:
  Console.WriteLine(label)
  For Each column As DataColumn In table.Columns
    Console.WriteLine("{0}{1}: {2}", ControlChars.Tab, _
      column.ColumnName, column.DataType.Name)
  Next column
End Sub

Comentários

Use o ReadXmlSchema método para criar o esquema para um DataTable. O esquema inclui definições de tabela, relação e restrição.

Para gravar um esquema em um documento XML, use o WriteXmlSchema método.

O esquema XML é interpretado de acordo com o padrão XSD.

A corrupção de dados poderá ocorrer se os tipos msdata:DataType e xs:type não corresponderem. Nenhuma exceção será gerada.

O ReadXmlSchema método geralmente é invocado antes de invocar o ReadXml método usado para preencher o DataTable.

Para criar uma relação aninhada usando o esquema XML, use elementos aninhados implícitos. Você também pode configurar a relação aninhada para usar nomes de coluna explícitos. Os elementos devem ser implicitamente aninhados para que os DataTables correspondentes participem de uma relação aninhada.

Confira também

Aplica-se a