DataTable.ReadXmlSchema 메서드

정의

XML 스키마를 읽습니다 DataTable.

오버로드

Name Description
ReadXmlSchema(XmlReader)

지정된 XmlReader을 사용하여 XML 스키마 DataTable 를 읽습니다.

ReadXmlSchema(String)

XML 스키마 DataTable 를 지정된 파일에서 읽습니다.

ReadXmlSchema(TextReader)

지정된 TextReader을 사용하여 XML 스키마 DataTable 를 읽습니다.

ReadXmlSchema(Stream)

지정된 스트림을 사용하여 XML 스키마 DataTable 를 읽습니다.

설명

메서드를 ReadXmlSchema 사용하여 에 대한 스키마를 만듭니다 DataTable. 스키마에는 테이블, 관계 및 제약 조건 정의가 포함됩니다.

XML 문서에 스키마를 쓰려면 이 메서드를 WriteXmlSchema 사용합니다.

XML 스키마는 XSD 표준에 따라 해석됩니다.

ReadXmlSchema 이 메서드는 일반적으로 를 채우는 데 사용되는 메서드를 ReadXml 호출하기 전에 호출됩니다DataTable.

ReadXmlSchema(XmlReader)

지정된 XmlReader을 사용하여 XML 스키마 DataTable 를 읽습니다.

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 스키마를 만들고 저장된 XML 스키마에서 해당 스키마 XmlTextReaderXmlReader를 원본으로 사용하여 읽습니다.

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 형식이 일치하지 않는 경우 데이터 손상이 발생할 수 있습니다. 예외가 throw되지 않습니다.

ReadXmlSchema 이 메서드는 일반적으로 를 채우는 데 사용되는 메서드를 ReadXml 호출하기 전에 호출됩니다DataTable.

메모

XML 스키마를 사용하여 중첩된 관계를 만드는 방법은 암시적 중첩 요소를 사용하는 것입니다. 또한 중첩된 관계를 다시 연결하여 명시적 열 이름을 사용할 수 있습니다. 해당 DataTable이 중첩된 관계로 참여하려면 요소를 암시적으로 중첩해야 합니다.

추가 정보

적용 대상

ReadXmlSchema(String)

XML 스키마 DataTable 를 지정된 파일에서 읽습니다.

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 형식이 일치하지 않는 경우 데이터 손상이 발생할 수 있습니다. 예외가 throw되지 않습니다.

ReadXmlSchema 이 메서드는 일반적으로 를 채우는 데 사용되는 메서드를 ReadXml 호출하기 전에 호출됩니다DataTable.

XML 스키마를 사용하여 중첩된 관계를 만들려면 암시적 중첩 요소를 사용합니다. 명시적 열 이름을 사용하도록 중첩된 관계를 다시 구성할 수도 있습니다. 해당 DataTable이 중첩된 관계로 참여하려면 요소를 암시적으로 중첩해야 합니다.

추가 정보

적용 대상

ReadXmlSchema(TextReader)

지정된 TextReader을 사용하여 XML 스키마 DataTable 를 읽습니다.

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 스키마를 만들고 저장된 XML 스키마에서 해당 스키마 StreamReaderTextReader를 원본으로 사용하여 읽습니다.

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 형식이 일치하지 않는 경우 데이터 손상이 발생할 수 있습니다. 예외가 throw되지 않습니다.

ReadXmlSchema 이 메서드는 일반적으로 를 채우는 데 사용되는 메서드를 ReadXml 호출하기 전에 호출됩니다DataTable.

XML 스키마를 사용하여 중첩된 관계를 만들려면 암시적 중첩 요소를 사용합니다. 명시적 열 이름을 사용하도록 중첩된 관계를 다시 구성할 수도 있습니다. 해당 DataTable이 중첩된 관계로 참여하려면 요소를 암시적으로 중첩해야 합니다.

추가 정보

적용 대상

ReadXmlSchema(Stream)

지정된 스트림을 사용하여 XML 스키마 DataTable 를 읽습니다.

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 형식이 일치하지 않는 경우 데이터 손상이 발생할 수 있습니다. 예외가 throw되지 않습니다.

ReadXmlSchema 이 메서드는 일반적으로 를 채우는 데 사용되는 메서드를 ReadXml 호출하기 전에 호출됩니다DataTable.

XML 스키마를 사용하여 중첩된 관계를 만들려면 암시적 중첩 요소를 사용합니다. 명시적 열 이름을 사용하도록 중첩된 관계를 구성할 수도 있습니다. 해당 DataTable이 중첩된 관계로 참여하려면 요소를 암시적으로 중첩해야 합니다.

추가 정보

적용 대상