DataTable.ReadXmlSchema メソッド

定義

XML スキーマを DataTable に読み込みます。

オーバーロード

ReadXmlSchema(XmlReader)

指定した DataTable を使用して、XML スキーマを XmlReader に読み込みます。

ReadXmlSchema(String)

指定したファイルから DataTable に XML スキーマを読み込みます。

ReadXmlSchema(TextReader)

指定した DataTable を使用して、XML スキーマを TextReader に読み込みます。

ReadXmlSchema(Stream)

指定したストリームを使用して、XML スキーマを DataTable に読み込みます。

注釈

メソッドを ReadXmlSchema 使用して、 のスキーマを DataTable作成します。 スキーマには、テーブル、リレーション、制約の定義が含まれます。

XML ドキュメントにスキーマを書き込むには、 メソッドを使用します WriteXmlSchema

XML スキーマは、XSD 標準に従って解釈されます。

メソッドはReadXmlSchema通常、 を埋DataTableめるために使用される メソッドをReadXml呼び出す前に呼び出されます。

ReadXmlSchema(XmlReader)

ソース:
DataTable.cs
ソース:
DataTable.cs
ソース:
DataTable.cs

指定した DataTable を使用して、XML スキーマを XmlReader に読み込みます。

public:
 void ReadXmlSchema(System::Xml::XmlReader ^ reader);
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)

パラメーター

reader
XmlReader

スキーマ情報を読み込むために使用する XmlReader

次のコンソール アプリケーションは、新しい DataTableを作成し、そのテーブルのスキーマを に MemoryStream書き込みます。 次に、新 DataTable しい を作成し、 (から継承される) をソースとして使用して XmlTextReader 、保存された XML スキーマから XmlReaderスキーマを読み取ります。

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

注釈

メソッドを ReadXmlSchema 使用して、 のスキーマを DataTable作成します。 スキーマには、テーブル、リレーション、制約の定義が含まれます。

XML ドキュメントにスキーマを書き込むには、 メソッドを使用します WriteXmlSchema

XML スキーマは、XSD 標準に従って解釈されます。

msdata:DataType 型と xs:type 型が一致しない場合、データの破損が発生する可能性があります。 例外はスローされません。

メソッドはReadXmlSchema通常、 を埋DataTableめるために使用される メソッドをReadXml呼び出す前に呼び出されます。

注意

XML スキーマを使用して入れ子になったリレーションシップを作成する方法は、暗黙的な入れ子になった要素を持つことです。 さらに、明示的な列名を使用するために、入れ子になったリレーションシップを再ワイヤードできます。 対応する DataTable が入れ子になったリレーションシップに参加するには、要素を暗黙的に入れ子にする必要があります。

こちらもご覧ください

適用対象

ReadXmlSchema(String)

ソース:
DataTable.cs
ソース:
DataTable.cs
ソース:
DataTable.cs

指定したファイルから DataTable に XML スキーマを読み込みます。

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

パラメーター

fileName
String

スキーマ情報の読み取り元のファイルの名前。

次のコンソール アプリケーションは、新しい DataTableを作成し、そのテーブルのスキーマをファイルに書き込みます。 次に、ファイルをソースとして使用して、新しい DataTable を作成し、保存した XML スキーマからスキーマを読み取ります。

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

注釈

メソッドを ReadXmlSchema 使用して、 のスキーマを DataTable作成します。 スキーマには、テーブル、リレーション、制約の定義が含まれます。

XML ドキュメントにスキーマを書き込むには、 メソッドを使用します WriteXmlSchema

XML スキーマは、XSD 標準に従って解釈されます。

msdata:DataType 型と xs:type 型が一致しない場合、データの破損が発生する可能性があります。 例外はスローされません。

メソッドはReadXmlSchema通常、 を埋DataTableめるために使用される メソッドをReadXml呼び出す前に呼び出されます。

XML スキーマを使用して入れ子になったリレーションシップを作成するには、暗黙的な入れ子になった要素を使用します。 明示的な列名を使用するように入れ子になった関係を再構成することもできます。 対応する DataTable が入れ子になったリレーションシップに参加するには、要素を暗黙的に入れ子にする必要があります。

こちらもご覧ください

適用対象

ReadXmlSchema(TextReader)

ソース:
DataTable.cs
ソース:
DataTable.cs
ソース:
DataTable.cs

指定した DataTable を使用して、XML スキーマを TextReader に読み込みます。

public:
 void ReadXmlSchema(System::IO::TextReader ^ reader);
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)

パラメーター

reader
TextReader

スキーマ情報を読み込むために使用する TextReader

次のコンソール アプリケーションは、新しい DataTableを作成し、そのテーブルのスキーマを に MemoryStream書き込みます。 次に、新 DataTable しい を作成し、 (から継承される) をソースとして使用して StreamReader 、保存された XML スキーマから TextReaderスキーマを読み取ります。

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

注釈

メソッドを ReadXmlSchema 使用して、 のスキーマを DataTable作成します。 スキーマには、テーブル、リレーション、制約の定義が含まれます。

XML ドキュメントにスキーマを書き込むには、 メソッドを使用します WriteXmlSchema

XML スキーマは、XSD 標準に従って解釈されます。

msdata:DataType 型と xs:type 型が一致しない場合、データの破損が発生する可能性があります。 例外はスローされません。

メソッドはReadXmlSchema通常、 を埋DataTableめるために使用される メソッドをReadXml呼び出す前に呼び出されます。

XML スキーマを使用して入れ子になったリレーションシップを作成するには、暗黙的な入れ子になった要素を使用します。 明示的な列名を使用するように入れ子になった関係を再構成することもできます。 対応する DataTable が入れ子になったリレーションシップに参加するには、要素を暗黙的に入れ子にする必要があります。

こちらもご覧ください

適用対象

ReadXmlSchema(Stream)

ソース:
DataTable.cs
ソース:
DataTable.cs
ソース:
DataTable.cs

指定したストリームを使用して、XML スキーマを DataTable に読み込みます。

public:
 void ReadXmlSchema(System::IO::Stream ^ stream);
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)

パラメーター

stream
Stream

スキーマを読み込むために使用するストリーム。

次のコンソール アプリケーションは、新しい DataTableを作成し、そのテーブルのスキーマを に MemoryStream書き込みます。 次に、新しい DataTable を作成し、保存された 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

注釈

メソッドを ReadXmlSchema 使用して、 のスキーマを DataTable作成します。 スキーマには、テーブル、リレーション、制約の定義が含まれます。

XML ドキュメントにスキーマを書き込むには、 メソッドを使用します WriteXmlSchema

XML スキーマは、XSD 標準に従って解釈されます。

msdata:DataType 型と xs:type 型が一致しない場合、データの破損が発生する可能性があります。 例外はスローされません。

メソッドはReadXmlSchema通常、 を埋DataTableめるために使用される メソッドをReadXml呼び出す前に呼び出されます。

XML スキーマを使用して入れ子になったリレーションシップを作成するには、暗黙的な入れ子になった要素を使用します。 明示的な列名を使用するように入れ子になったリレーションシップを構成することもできます。 対応する DataTable が入れ子になったリレーションシップに参加するには、要素を暗黙的に入れ子にする必要があります。

こちらもご覧ください

適用対象