DataTable.ReadXmlSchema Metoda

Definice

Načte schéma XML do souboru DataTable.

Přetížení

Name Description
ReadXmlSchema(XmlReader)

Načte schéma XML do zadaného schématu DataTableXmlReader.

ReadXmlSchema(String)

Načte schéma XML do DataTable zadaného souboru.

ReadXmlSchema(TextReader)

Načte schéma XML do zadaného schématu DataTableTextReader.

ReadXmlSchema(Stream)

Načte schéma XML do zadaného datového DataTable proudu.

Poznámky

Použijte metodu ReadXmlSchema k vytvoření schématu pro .DataTable Schéma obsahuje definice tabulek, relací a omezení.

K zápisu schématu do dokumentu XML použijte metodu WriteXmlSchema .

Schéma XML se interpretuje podle standardu XSD.

Metoda ReadXmlSchema je obecně vyvolána před vyvoláním ReadXml metody, která se používá k vyplnění DataTable.

ReadXmlSchema(XmlReader)

Zdroj:
DataTable.cs
Zdroj:
DataTable.cs
Zdroj:
DataTable.cs
Zdroj:
DataTable.cs
Zdroj:
DataTable.cs

Načte schéma XML do zadaného schématu DataTableXmlReader.

public:
 void ReadXmlSchema(System::Xml::XmlReader ^ reader);
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Members from serialized types may use dynamic code generation.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
public void ReadXmlSchema(System.Xml.XmlReader? reader);
public void ReadXmlSchema(System.Xml.XmlReader? reader);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
public void ReadXmlSchema(System.Xml.XmlReader? reader);
public void ReadXmlSchema(System.Xml.XmlReader reader);
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Members from serialized types may use dynamic code generation.")>]
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")>]
member this.ReadXmlSchema : System.Xml.XmlReader -> unit
member this.ReadXmlSchema : System.Xml.XmlReader -> unit
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")>]
member this.ReadXmlSchema : System.Xml.XmlReader -> unit
Public Sub ReadXmlSchema (reader As XmlReader)

Parametry

reader
XmlReader

Slouží XmlReader ke čtení informací o schématu.

Atributy

Příklady

Následující konzolová aplikace vytvoří novou DataTablea zapíše schéma pro danou tabulku do objektu MemoryStream. Potom příklad vytvoří nové DataTable schéma a načte jeho schéma z uloženého schématu XML pomocí objektu XmlTextReader (který dědí z XmlReader) jako jeho zdroj.

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

Poznámky

Použijte metodu ReadXmlSchema k vytvoření schématu pro .DataTable Schéma obsahuje definice tabulek, relací a omezení.

K zápisu schématu do dokumentu XML použijte metodu WriteXmlSchema .

Schéma XML se interpretuje podle standardu XSD.

K poškození dat může dojít, pokud se typy msdata:DataType a xs:type neshodují. Nevyvolá se žádná výjimka.

Metoda ReadXmlSchema je obecně vyvolána před vyvoláním ReadXml metody, která se používá k vyplnění DataTable.

Note

Způsob, jak vytvořit vnořenou relaci pomocí schématu XML, je mít implicitní vnořené elementy. Navíc může být vnořená relace znovu připojena, aby bylo možné použít explicitní názvy sloupců. Je povinné, aby prvky byly implicitně vnořené pro odpovídající datové tabulky, aby se účastnily vnořené relace.

Viz také

Platí pro

ReadXmlSchema(String)

Zdroj:
DataTable.cs
Zdroj:
DataTable.cs
Zdroj:
DataTable.cs
Zdroj:
DataTable.cs
Zdroj:
DataTable.cs

Načte schéma XML do DataTable zadaného souboru.

public:
 void ReadXmlSchema(System::String ^ fileName);
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Members from serialized types may use dynamic code generation.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
public void ReadXmlSchema(string fileName);
public void ReadXmlSchema(string fileName);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
public void ReadXmlSchema(string fileName);
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Members from serialized types may use dynamic code generation.")>]
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")>]
member this.ReadXmlSchema : string -> unit
member this.ReadXmlSchema : string -> unit
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")>]
member this.ReadXmlSchema : string -> unit
Public Sub ReadXmlSchema (fileName As String)

Parametry

fileName
String

Název souboru, ze kterého chcete přečíst informace o schématu.

Atributy

Příklady

Následující konzolová aplikace vytvoří novou DataTablea zapíše schéma pro danou tabulku do souboru. Pak příklad vytvoří nové DataTable schéma a načte jeho schéma z uloženého schématu XML pomocí souboru jako jeho zdroje.

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

Poznámky

Použijte metodu ReadXmlSchema k vytvoření schématu pro .DataTable Schéma obsahuje definice tabulek, relací a omezení.

K zápisu schématu do dokumentu XML použijte metodu WriteXmlSchema .

Schéma XML se interpretuje podle standardu XSD.

K poškození dat může dojít, pokud se typy msdata:DataType a xs:type neshodují. Nevyvolá se žádná výjimka.

Metoda ReadXmlSchema je obecně vyvolána před vyvoláním ReadXml metody, která se používá k vyplnění DataTable.

Pokud chcete vytvořit vnořenou relaci pomocí schématu XML, použijte implicitní vnořené elementy. Můžete také překonfigurovat vnořenou relaci tak, aby používala explicitní názvy sloupců. Elementy musí být implicitně vnořené, aby se odpovídající datové tabulky mohly účastnit vnořené relace.

Viz také

Platí pro

ReadXmlSchema(TextReader)

Zdroj:
DataTable.cs
Zdroj:
DataTable.cs
Zdroj:
DataTable.cs
Zdroj:
DataTable.cs
Zdroj:
DataTable.cs

Načte schéma XML do zadaného schématu DataTableTextReader.

public:
 void ReadXmlSchema(System::IO::TextReader ^ reader);
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Members from serialized types may use dynamic code generation.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
public void ReadXmlSchema(System.IO.TextReader? reader);
public void ReadXmlSchema(System.IO.TextReader? reader);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
public void ReadXmlSchema(System.IO.TextReader? reader);
public void ReadXmlSchema(System.IO.TextReader reader);
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Members from serialized types may use dynamic code generation.")>]
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")>]
member this.ReadXmlSchema : System.IO.TextReader -> unit
member this.ReadXmlSchema : System.IO.TextReader -> unit
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")>]
member this.ReadXmlSchema : System.IO.TextReader -> unit
Public Sub ReadXmlSchema (reader As TextReader)

Parametry

reader
TextReader

Slouží TextReader ke čtení informací o schématu.

Atributy

Příklady

Následující konzolová aplikace vytvoří novou DataTablea zapíše schéma pro danou tabulku do objektu MemoryStream. Potom příklad vytvoří nové DataTable schéma a načte jeho schéma z uloženého schématu XML pomocí objektu StreamReader (který dědí z TextReader) jako jeho zdroj.

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

Poznámky

Použijte metodu ReadXmlSchema k vytvoření schématu pro .DataTable Schéma obsahuje definice tabulek, relací a omezení.

K zápisu schématu do dokumentu XML použijte metodu WriteXmlSchema .

Schéma XML se interpretuje podle standardu XSD.

K poškození dat může dojít, pokud se typy msdata:DataType a xs:type neshodují. Nevyvolá se žádná výjimka.

Metoda ReadXmlSchema je obecně vyvolána před vyvoláním ReadXml metody, která se používá k vyplnění DataTable.

Pokud chcete vytvořit vnořenou relaci pomocí schématu XML, použijte implicitní vnořené elementy. Můžete také překonfigurovat vnořenou relaci tak, aby používala explicitní názvy sloupců. Elementy musí být implicitně vnořené, aby se odpovídající datové tabulky mohly účastnit vnořené relace.

Viz také

Platí pro

ReadXmlSchema(Stream)

Zdroj:
DataTable.cs
Zdroj:
DataTable.cs
Zdroj:
DataTable.cs
Zdroj:
DataTable.cs
Zdroj:
DataTable.cs

Načte schéma XML do zadaného datového DataTable proudu.

public:
 void ReadXmlSchema(System::IO::Stream ^ stream);
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Members from serialized types may use dynamic code generation.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
public void ReadXmlSchema(System.IO.Stream? stream);
public void ReadXmlSchema(System.IO.Stream? stream);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
public void ReadXmlSchema(System.IO.Stream? stream);
public void ReadXmlSchema(System.IO.Stream stream);
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Members from serialized types may use dynamic code generation.")>]
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")>]
member this.ReadXmlSchema : System.IO.Stream -> unit
member this.ReadXmlSchema : System.IO.Stream -> unit
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")>]
member this.ReadXmlSchema : System.IO.Stream -> unit
Public Sub ReadXmlSchema (stream As Stream)

Parametry

stream
Stream

Datový proud použitý ke čtení schématu.

Atributy

Příklady

Následující konzolová aplikace vytvoří novou DataTablea zapíše schéma pro danou tabulku do objektu MemoryStream. Pak příklad vytvoří nový DataTable a načte jeho schéma z uloženého schématu XML.

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

Poznámky

Použijte metodu ReadXmlSchema k vytvoření schématu pro .DataTable Schéma obsahuje definice tabulek, relací a omezení.

K zápisu schématu do dokumentu XML použijte metodu WriteXmlSchema .

Schéma XML se interpretuje podle standardu XSD.

K poškození dat může dojít, pokud se typy msdata:DataType a xs:type neshodují. Nevyvolá se žádná výjimka.

Metoda ReadXmlSchema je obecně vyvolána před vyvoláním ReadXml metody, která se používá k vyplnění DataTable.

Pokud chcete vytvořit vnořenou relaci pomocí schématu XML, použijte implicitní vnořené elementy. Vnořenou relaci můžete také nakonfigurovat tak, aby používala explicitní názvy sloupců. Elementy musí být implicitně vnořené, aby se odpovídající datové tabulky mohly účastnit vnořené relace.

Viz také

Platí pro