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

Definición

Lee un esquema XML en el objeto DataTable.Reads an XML schema into the DataTable.

Sobrecargas

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

Lee un esquema XML en el objeto DataTable utilizando el objeto XmlReader especificado.Reads an XML schema into the DataTable using the specified XmlReader.

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

Lee un esquema XML en el objeto DataTable desde el archivo especificado.Reads an XML schema into the DataTable from the specified file.

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

Lee un esquema XML en el objeto DataTable utilizando el objeto TextReader especificado.Reads an XML schema into the DataTable using the specified TextReader.

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

Lee un esquema XML en el objeto DataTable utilizando la secuencia especificada.Reads an XML schema into the DataTable using the specified stream.

Comentarios

Utilice el ReadXmlSchema método para crear el esquema DataTablepara.Use the ReadXmlSchema method to create the schema for a DataTable. El esquema incluye definiciones de tablas, relaciones y restricciones.The schema includes table, relation, and constraint definitions.

Para escribir un esquema en un documento XML, utilice el WriteXmlSchema método.To write a schema to an XML document, use the WriteXmlSchema method.

El esquema XML se interpreta según el estándar XSD.The XML schema is interpreted according to the XSD standard.

Normalmente ReadXmlSchema se invoca el método antes de invocar el ReadXml método que se usa para rellenar el 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)

Lee un esquema XML en el objeto DataTable utilizando el objeto XmlReader especificado.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)

Parámetros

reader
XmlReader XmlReader XmlReader XmlReader

Objeto XmlReader que se utiliza para leer la información del esquema.The XmlReader used to read the schema information.

Ejemplos

La siguiente aplicación de consola crea un DataTablenuevo y escribe el esquema de esa tabla MemoryStreamen.The following console application creates a new DataTable, and writes the schema for that table to a MemoryStream. A continuación, en el ejemplo se DataTable crea un nuevo y se lee su esquema a partir del esquema XmlTextReader XML guardado, utilizando un XmlReader(que hereda de) como su origen.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

Comentarios

Utilice el ReadXmlSchema método para crear el esquema DataTablepara.Use the ReadXmlSchema method to create the schema for a DataTable. El esquema incluye definiciones de tablas, relaciones y restricciones.The schema includes table, relation, and constraint definitions.

Para escribir un esquema en un documento XML, utilice el WriteXmlSchema método.To write a schema to an XML document, use the WriteXmlSchema method.

El esquema XML se interpreta según el estándar XSD.The XML schema is interpreted according to the XSD standard.

Pueden producirse daños en los datos si los tipos msdata: DataType y XS: Type no coinciden.Data corruption can occur if the msdata:DataType and the xs:type types do not match. No se producirá ninguna excepción.No exception will be thrown.

Normalmente ReadXmlSchema se invoca el método antes de invocar el ReadXml método que se usa para rellenar el DataTable.The ReadXmlSchema method is generally invoked before invoking the ReadXml method which is used to fill the DataTable.

Nota

La manera de crear una relación anidada mediante el esquema XML es tener elementos anidados implícitos.The way to create a nested relation using XML schema is to have implicit nested elements. Además, se podría volver a establecer la relación anidada para utilizar nombres de columna explícitos.Additionally, the nested relation could be re-wired, to use explicit column names. Es obligatorio que los elementos se aniden implícitamente para que las DataTables correspondientes participen en una relación anidada.It is mandatory for elements to be implicitly nested for the corresponding DataTables to participate in a nested relation.

Consulte también:

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

Lee un esquema XML en el objeto DataTable desde el archivo especificado.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)

Parámetros

fileName
String String String String

Nombre del archivo del que se va a leer la información de esquema.The name of the file from which to read the schema information.

Ejemplos

La siguiente aplicación de consola crea un DataTablenuevo y escribe el esquema de la tabla en un archivo.The following console application creates a new DataTable, and writes the schema for that table to a file. A continuación, en el ejemplo se DataTable crea un nuevo y se lee su esquema a partir del esquema XML guardado, utilizando el archivo como su origen.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

Comentarios

Utilice el ReadXmlSchema método para crear el esquema DataTablepara.Use the ReadXmlSchema method to create the schema for a DataTable. El esquema incluye definiciones de tablas, relaciones y restricciones.The schema includes table, relation, and constraint definitions.

Para escribir un esquema en un documento XML, utilice el WriteXmlSchema método.To write a schema to an XML document, use the WriteXmlSchema method.

El esquema XML se interpreta según el estándar XSD.The XML schema is interpreted according to the XSD standard.

Pueden producirse daños en los datos si los tipos msdata: DataType y XS: Type no coinciden.Data corruption can occur if the msdata:DataType and the xs:type types do not match. No se producirá ninguna excepción.No exception will be thrown.

Normalmente ReadXmlSchema se invoca el método antes de invocar el ReadXml método que se usa para rellenar el DataTable.The ReadXmlSchema method is generally invoked before invoking the ReadXml method which is used to fill the DataTable.

Para crear una relación anidada mediante un esquema XML, use elementos anidados implícitos.To create a nested relation using XML schema, use implicit nested elements. También puede volver a configurar la relación anidada para utilizar nombres de columna explícitos.You can also reconfigure the nested relation to use explicit column names. Los elementos deben estar anidados de forma implícita para que las tablas DataTable correspondientes participen en una relación anidada.Elements must be implicitly nested in order for the corresponding DataTables to participate in a nested relation.

Consulte también:

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

Lee un esquema XML en el objeto DataTable utilizando el objeto TextReader especificado.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)

Parámetros

reader
TextReader TextReader TextReader TextReader

Objeto TextReader que se utiliza para leer la información del esquema.The TextReader used to read the schema information.

Ejemplos

La siguiente aplicación de consola crea un DataTablenuevo y escribe el esquema de esa tabla MemoryStreamen.The following console application creates a new DataTable, and writes the schema for that table to a MemoryStream. A continuación, en el ejemplo se DataTable crea un nuevo y se lee su esquema a partir del esquema StreamReader XML guardado, utilizando un TextReader(que hereda de) como su origen.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

Comentarios

Utilice el ReadXmlSchema método para crear el esquema DataTablepara.Use the ReadXmlSchema method to create the schema for a DataTable. El esquema incluye definiciones de tablas, relaciones y restricciones.The schema includes table, relation, and constraint definitions.

Para escribir un esquema en un documento XML, utilice el WriteXmlSchema método.To write a schema to an XML document, use the WriteXmlSchema method.

El esquema XML se interpreta según el estándar XSD.The XML schema is interpreted according to the XSD standard.

Pueden producirse daños en los datos si los tipos msdata: DataType y XS: Type no coinciden.Data corruption can occur if the msdata:DataType and the xs:type types do not match. No se producirá ninguna excepción.No exception will be thrown.

Normalmente ReadXmlSchema se invoca el método antes de invocar el ReadXml método que se usa para rellenar el DataTable.The ReadXmlSchema method is generally invoked before invoking the ReadXml method which is used to fill the DataTable.

Para crear una relación anidada mediante un esquema XML, use elementos anidados implícitos.To create a nested relation using XML schema, use implicit nested elements. También puede volver a configurar la relación anidada para utilizar nombres de columna explícitos.You can also reconfigure the nested relation to use explicit column names. Los elementos deben estar anidados de forma implícita para que las tablas DataTable correspondientes participen en una relación anidada.Elements must be implicitly nested in order for the corresponding DataTables to participate in a nested relation.

Consulte también:

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

Lee un esquema XML en el objeto DataTable utilizando la secuencia especificada.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

Parámetros

stream
Stream Stream Stream Stream

Secuencia que se utiliza para leer el esquema.The stream used to read the schema.

Ejemplos

La siguiente aplicación de consola crea un DataTablenuevo y escribe el esquema de esa tabla MemoryStreamen.The following console application creates a new DataTable, and writes the schema for that table to a MemoryStream. A continuación, en el ejemplo se DataTable crea un nuevo y se lee su esquema a partir del esquema XML guardado.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

Comentarios

Utilice el ReadXmlSchema método para crear el esquema DataTablepara.Use the ReadXmlSchema method to create the schema for a DataTable. El esquema incluye definiciones de tablas, relaciones y restricciones.The schema includes table, relation, and constraint definitions.

Para escribir un esquema en un documento XML, utilice el WriteXmlSchema método.To write a schema to an XML document, use the WriteXmlSchema method.

El esquema XML se interpreta según el estándar XSD.The XML schema is interpreted according to the XSD standard.

Pueden producirse daños en los datos si los tipos msdata: DataType y XS: Type no coinciden.Data corruption can occur if the msdata:DataType and the xs:type types do not match. No se producirá ninguna excepción.No exception will be thrown.

Normalmente ReadXmlSchema se invoca el método antes de invocar el ReadXml método que se usa para rellenar el DataTable.The ReadXmlSchema method is generally invoked before invoking the ReadXml method which is used to fill the DataTable.

Para crear una relación anidada mediante un esquema XML, use elementos anidados implícitos.To create a nested relation using XML schema, use implicit nested elements. También puede configurar la relación anidada para utilizar nombres de columna explícitos.You can also configure the nested relation to use explicit column names. Los elementos deben estar anidados de forma implícita para que las tablas DataTable correspondientes participen en una relación anidada.Elements must be implicitly nested in order for the corresponding DataTables to participate in a nested relation.

Consulte también:

Se aplica a