DataTable.ReadXmlSchemaとは? わかりやすく解説

DataTable.ReadXmlSchema メソッド (String)

メモ : このメソッドは、.NET Framework version 2.0新しく追加されたものです。

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

名前空間: System.Data
アセンブリ: System.Data (system.data.dll 内)
構文構文

Public Sub ReadXmlSchema ( _
    fileName As String _
)
Dim instance As DataTable
Dim fileName As String

instance.ReadXmlSchema(fileName)
public void ReadXmlSchema (
    string fileName
)
public:
void ReadXmlSchema (
    String^ fileName
)
public void ReadXmlSchema (
    String fileName
)
public function ReadXmlSchema (
    fileName : String
)

パラメータ

fileName

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

解説解説
使用例使用例

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

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
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();
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

DataTable.ReadXmlSchema メソッド (TextReader)

メモ : このメソッドは、.NET Framework version 2.0新しく追加されたものです。

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

名前空間: System.Data
アセンブリ: System.Data (system.data.dll 内)
構文構文

Public Sub ReadXmlSchema ( _
    reader As TextReader _
)
Dim instance As DataTable
Dim reader As TextReader

instance.ReadXmlSchema(reader)
public void ReadXmlSchema (
    TextReader reader
)
public:
void ReadXmlSchema (
    TextReader^ reader
)
public void ReadXmlSchema (
    TextReader reader
)
public function ReadXmlSchema (
    reader : TextReader
)

パラメータ

reader

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

解説解説
使用例使用例

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

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
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();
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

DataTable.ReadXmlSchema メソッド (Stream)

メモ : このメソッドは、.NET Framework version 2.0新しく追加されたものです。

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

名前空間: System.Data
アセンブリ: System.Data (system.data.dll 内)
構文構文

Public Sub ReadXmlSchema ( _
    stream As Stream _
)
Dim instance As DataTable
Dim stream As Stream

instance.ReadXmlSchema(stream)
public void ReadXmlSchema (
    Stream stream
)
public:
void ReadXmlSchema (
    Stream^ stream
)
public void ReadXmlSchema (
    Stream stream
)
public function ReadXmlSchema (
    stream : Stream
)

パラメータ

stream

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

解説解説
使用例使用例

次に示すコンソール アプリケーションの例では、新しDataTable作成し、このテーブルスキーマを MemoryStream に書き込みます次に新しDataTable作成し、そのスキーマ保存済み XML スキーマから読み取ります。

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
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();
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
DataTable クラス
DataTable メンバ
System.Data 名前空間
DataSet.ReadXmlSchema
ReadXmlSchema
その他の技術情報
DataTable の作成使用
DataTable の作成使用

DataTable.ReadXmlSchema メソッド (XmlReader)

メモ : このメソッドは、.NET Framework version 2.0新しく追加されたものです。

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

名前空間: System.Data
アセンブリ: System.Data (system.data.dll 内)
構文構文

解説解説
使用例使用例

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

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
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();
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

DataTable.ReadXmlSchema メソッド

XML スキーマを DataTable に読み込みます。
オーバーロードの一覧オーバーロードの一覧

参照参照

関連項目

DataTable クラス
DataTable メンバ
System.Data 名前空間
DataSet.ReadXmlSchema
ReadXmlSchema

その他の技術情報

DataTable の作成使用
DataTable の作成使用
DataTable の作成使用 ReadXmlSchema


このページでは「.NET Framework クラス ライブラリ リファレンス」からDataTable.ReadXmlSchemaを検索した結果を表示しています。
Weblioに収録されているすべての辞書からDataTable.ReadXmlSchemaを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からDataTable.ReadXmlSchema を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

カテゴリ一覧

すべての辞書の索引



Weblioのサービス

「DataTable.ReadXmlSchema」の関連用語


DataTable.ReadXmlSchemaのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



DataTable.ReadXmlSchemaのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS