DataTable.ReadXmlSchema DataTable.ReadXmlSchema DataTable.ReadXmlSchema DataTable.ReadXmlSchema Method

Definizione

Legge un XML Schema in DataTable.Reads an XML schema into the DataTable.

Overload

ReadXmlSchema(XmlReader) ReadXmlSchema(XmlReader) ReadXmlSchema(XmlReader) ReadXmlSchema(XmlReader)

Legge uno schema XML nella classe DataTable, utilizzando la classe XmlReader specificata.Reads an XML schema into the DataTable using the specified XmlReader.

ReadXmlSchema(String) ReadXmlSchema(String) ReadXmlSchema(String) ReadXmlSchema(String)

Legge uno schema XML nella classe DataTable dal file specificato.Reads an XML schema into the DataTable from the specified file.

ReadXmlSchema(TextReader) ReadXmlSchema(TextReader) ReadXmlSchema(TextReader) ReadXmlSchema(TextReader)

Legge uno schema XML nella classe DataTable, utilizzando la classe TextReader specificata.Reads an XML schema into the DataTable using the specified TextReader.

ReadXmlSchema(Stream) ReadXmlSchema(Stream) ReadXmlSchema(Stream)

Legge uno schema XML nella classe DataTable, utilizzando il flusso specificato.Reads an XML schema into the DataTable using the specified stream.

Commenti

Usare la ReadXmlSchema metodo per creare lo schema per un DataTable.Use the ReadXmlSchema method to create the schema for a DataTable. Lo schema include le definizioni di tabella, relazioni e vincoli.The schema includes table, relation, and constraint definitions.

Per scrivere uno schema a un documento XML, usare il WriteXmlSchema (metodo).To write a schema to an XML document, use the WriteXmlSchema method.

Lo schema XML viene interpretato in base a XSD standard.The XML schema is interpreted according to the XSD standard.

Il ReadXmlSchema metodo in genere viene richiamato prima di richiamare il ReadXml metodo utilizzato per riempire il DataTable.The ReadXmlSchema method is generally invoked before invoking the ReadXml method which is used to fill the DataTable.

ReadXmlSchema(XmlReader) ReadXmlSchema(XmlReader) ReadXmlSchema(XmlReader) ReadXmlSchema(XmlReader)

Legge uno schema XML nella classe DataTable, utilizzando la classe XmlReader specificata.Reads an XML schema into the DataTable using the specified 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)

Parametri

reader
XmlReader XmlReader XmlReader XmlReader

Classe XmlReader utilizzata per leggere le informazioni dello schema.The XmlReader used to read the schema information.

Esempi

La seguente applicazione console crea un nuovo DataTablee scrive lo schema per tale tabella impostando un MemoryStream.The following console application creates a new DataTable, and writes the schema for that table to a MemoryStream. Quindi, nell'esempio viene creato un nuovo DataTable e legge lo schema di XML schema salvato, usando una XmlTextReader (che eredita da XmlReader) come origine.Then, the example creates a new DataTable and reads its schema from the saved XML schema, using a XmlTextReader (which inherits from XmlReader) as its source.

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

Commenti

Usare la ReadXmlSchema metodo per creare lo schema per un DataTable.Use the ReadXmlSchema method to create the schema for a DataTable. Lo schema include le definizioni di tabella, relazioni e vincoli.The schema includes table, relation, and constraint definitions.

Per scrivere uno schema a un documento XML, usare il WriteXmlSchema (metodo).To write a schema to an XML document, use the WriteXmlSchema method.

Lo schema XML viene interpretato in base a XSD standard.The XML schema is interpreted according to the XSD standard.

Il danneggiamento dei dati può verificarsi se il DataType e i tipi xs: Type non corrispondono.Data corruption can occur if the msdata:DataType and the xs:type types do not match. Non verrà generata alcuna eccezione.No exception will be thrown.

Il ReadXmlSchema metodo in genere viene richiamato prima di richiamare il ReadXml metodo utilizzato per riempire il DataTable.The ReadXmlSchema method is generally invoked before invoking the ReadXml method which is used to fill the DataTable.

Nota

Il modo per creare una relazione annidata utilizzando uno schema XML è contenere elementi nidificati impliciti.The way to create a nested relation using XML schema is to have implicit nested elements. Inoltre, la relazione nidificata potrebbe essere nuovamente cablata, usare nomi di colonna espliciti.Additionally, the nested relation could be re-wired, to use explicit column names. È obbligatorio, gli elementi devono essere annidato in modo implicito per DataTable corrispondente a far parte di una relazione annidata.It is mandatory for elements to be implicitly nested for the corresponding DataTables to participate in a nested relation.

Vedi anche

ReadXmlSchema(String) ReadXmlSchema(String) ReadXmlSchema(String) ReadXmlSchema(String)

Legge uno schema XML nella classe DataTable dal file specificato.Reads an XML schema into the DataTable from the specified file.

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

Parametri

fileName
String String String String

Nome del file dal quale leggere le informazioni dello schema.The name of the file from which to read the schema information.

Esempi

La seguente applicazione console crea un nuovo DataTablee scrive lo schema per la tabella in un file.The following console application creates a new DataTable, and writes the schema for that table to a file. Quindi, nell'esempio viene creato un nuovo DataTable e legge lo schema di XML schema salvato, utilizzare il file come origine.Then, the example creates a new DataTable and reads its schema from the saved XML schema, using the file as its source.

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

Commenti

Usare la ReadXmlSchema metodo per creare lo schema per un DataTable.Use the ReadXmlSchema method to create the schema for a DataTable. Lo schema include le definizioni di tabella, relazioni e vincoli.The schema includes table, relation, and constraint definitions.

Per scrivere uno schema a un documento XML, usare il WriteXmlSchema (metodo).To write a schema to an XML document, use the WriteXmlSchema method.

Lo schema XML viene interpretato in base a XSD standard.The XML schema is interpreted according to the XSD standard.

Il danneggiamento dei dati può verificarsi se il DataType e i tipi xs: Type non corrispondono.Data corruption can occur if the msdata:DataType and the xs:type types do not match. Non verrà generata alcuna eccezione.No exception will be thrown.

Il ReadXmlSchema metodo in genere viene richiamato prima di richiamare il ReadXml metodo utilizzato per riempire il DataTable.The ReadXmlSchema method is generally invoked before invoking the ReadXml method which is used to fill the DataTable.

Per creare una relazione annidata utilizzando XML schema, usare gli elementi annidati impliciti.To create a nested relation using XML schema, use implicit nested elements. È anche possibile riconfigurare la relazione annidata per l'uso di nomi di colonna espliciti.You can also reconfigure the nested relation to use explicit column names. Elementi devono essere annidati in modo implicito affinché il DataTable corrispondente a far parte di una relazione annidata.Elements must be implicitly nested in order for the corresponding DataTables to participate in a nested relation.

Vedi anche

ReadXmlSchema(TextReader) ReadXmlSchema(TextReader) ReadXmlSchema(TextReader) ReadXmlSchema(TextReader)

Legge uno schema XML nella classe DataTable, utilizzando la classe TextReader specificata.Reads an XML schema into the DataTable using the specified 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)

Parametri

reader
TextReader TextReader TextReader TextReader

Classe TextReader utilizzata per leggere le informazioni dello schema.The TextReader used to read the schema information.

Esempi

La seguente applicazione console crea un nuovo DataTablee scrive lo schema per tale tabella impostando un MemoryStream.The following console application creates a new DataTable, and writes the schema for that table to a MemoryStream. Quindi, nell'esempio viene creato un nuovo DataTable e legge lo schema di XML schema salvato, usando una StreamReader (che eredita da TextReader) come origine.Then, the example creates a new DataTable and reads its schema from the saved XML schema, using a StreamReader (which inherits from TextReader) as its source.

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

Commenti

Usare la ReadXmlSchema metodo per creare lo schema per un DataTable.Use the ReadXmlSchema method to create the schema for a DataTable. Lo schema include le definizioni di tabella, relazioni e vincoli.The schema includes table, relation, and constraint definitions.

Per scrivere uno schema a un documento XML, usare il WriteXmlSchema (metodo).To write a schema to an XML document, use the WriteXmlSchema method.

Lo schema XML viene interpretato in base a XSD standard.The XML schema is interpreted according to the XSD standard.

Il danneggiamento dei dati può verificarsi se il DataType e i tipi xs: Type non corrispondono.Data corruption can occur if the msdata:DataType and the xs:type types do not match. Non verrà generata alcuna eccezione.No exception will be thrown.

Il ReadXmlSchema metodo in genere viene richiamato prima di richiamare il ReadXml metodo utilizzato per riempire il DataTable.The ReadXmlSchema method is generally invoked before invoking the ReadXml method which is used to fill the DataTable.

Per creare una relazione annidata utilizzando XML schema, usare gli elementi annidati impliciti.To create a nested relation using XML schema, use implicit nested elements. È anche possibile riconfigurare la relazione annidata per l'uso di nomi di colonna espliciti.You can also reconfigure the nested relation to use explicit column names. Elementi devono essere annidati in modo implicito affinché il DataTable corrispondente a far parte di una relazione annidata.Elements must be implicitly nested in order for the corresponding DataTables to participate in a nested relation.

Vedi anche

ReadXmlSchema(Stream) ReadXmlSchema(Stream) ReadXmlSchema(Stream)

Legge uno schema XML nella classe DataTable, utilizzando il flusso specificato.Reads an XML schema into the DataTable using the specified stream.

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

Parametri

stream
Stream Stream Stream Stream

Flusso utilizzato per leggere lo schema.The stream used to read the schema.

Esempi

La seguente applicazione console crea un nuovo DataTablee scrive lo schema per tale tabella impostando un MemoryStream.The following console application creates a new DataTable, and writes the schema for that table to a MemoryStream. Quindi, nell'esempio viene creato un nuovo DataTable e legge lo schema di XML schema salvato.Then, the example creates a new DataTable and reads its schema from the saved XML schema.

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

Commenti

Usare la ReadXmlSchema metodo per creare lo schema per un DataTable.Use the ReadXmlSchema method to create the schema for a DataTable. Lo schema include le definizioni di tabella, relazioni e vincoli.The schema includes table, relation, and constraint definitions.

Per scrivere uno schema a un documento XML, usare il WriteXmlSchema (metodo).To write a schema to an XML document, use the WriteXmlSchema method.

Lo schema XML viene interpretato in base a XSD standard.The XML schema is interpreted according to the XSD standard.

Il danneggiamento dei dati può verificarsi se il DataType e i tipi xs: Type non corrispondono.Data corruption can occur if the msdata:DataType and the xs:type types do not match. Non verrà generata alcuna eccezione.No exception will be thrown.

Il ReadXmlSchema metodo in genere viene richiamato prima di richiamare il ReadXml metodo utilizzato per riempire il DataTable.The ReadXmlSchema method is generally invoked before invoking the ReadXml method which is used to fill the DataTable.

Per creare una relazione annidata utilizzando XML schema, usare gli elementi annidati impliciti.To create a nested relation using XML schema, use implicit nested elements. È anche possibile configurare la relazione annidata per l'uso di nomi di colonna espliciti.You can also configure the nested relation to use explicit column names. Elementi devono essere annidati in modo implicito affinché il DataTable corrispondente a far parte di una relazione annidata.Elements must be implicitly nested in order for the corresponding DataTables to participate in a nested relation.

Vedi anche

Si applica a