DataSet.ReadXmlSchema 方法

定义

将 XML 架构读入 DataSetReads an XML schema into the DataSet.

重载

ReadXmlSchema(Stream)

从指定的 Stream 中将 XML 架构读入 DataSetReads the XML schema from the specified Stream into the DataSet.

ReadXmlSchema(TextReader)

从指定的 TextReader 中将 XML 架构读入 DataSetReads the XML schema from the specified TextReader into the DataSet.

ReadXmlSchema(String)

从指定的文件中将 XML 架构读入 DataSetReads the XML schema from the specified file into the DataSet.

ReadXmlSchema(XmlReader)

从指定的 XmlReader 中将 XML 架构读入 DataSetReads the XML schema from the specified XmlReader into the DataSet.

ReadXmlSchema(Stream)

从指定的 Stream 中将 XML 架构读入 DataSetReads the XML schema from the specified Stream into the DataSet.

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

参数

stream
Stream

从中读取的 StreamThe Stream from which to read.

示例

下面的示例创建一个 FileStream 对象以便使用来读取 XML 架构,并使用该对象调用 ReadXmlSchema 方法。The following example creates a FileStream object to read an XML schema with, and invokes the ReadXmlSchema method with the object.

private void ReadSchemaFromFileStream(DataSet thisDataSet)
{
    // Set the file path and name.
    // Modify this for your purposes.
    string filename="Schema.xml";

    // Create the FileStream object with the file name, 
    // and set to open the file.
    System.IO.FileStream stream = 
        new System.IO.FileStream(filename,System.IO.FileMode.Open);

    // Read the schema into the DataSet.
    thisDataSet.ReadXmlSchema(stream);

    // Close the FileStream.
    stream.Close();
}
Private Sub ReadSchemaFromFileStream(thisDataSet As DataSet)
    ' Set the file path and name. Modify this for your purposes.
    Dim filename As String = "Schema.xml"

    ' Create the FileStream object with the file name, 
    ' and set to open the file
    Dim stream As New System.IO.FileStream _
        (filename, System.IO.FileMode.Open)

    ' Read the schema into the DataSet.
    thisDataSet.ReadXmlSchema(stream)

    ' Close the FileStream.
    stream.Close()
End Sub

注解

使用 ReadXmlSchema 方法为 DataSet创建架构。Use the ReadXmlSchema method to create the schema for a DataSet. 此架构包括表、关系和约束定义。The schema includes table, relation, and constraint definitions. 若要将架构写入 XML 文档,请使用 WriteXmlSchema 方法。To write a schema to an XML document, use the WriteXmlSchema method.

使用 XSD 标准编写 XML 架构。The XML schema is written using the XSD standard.

备注

如果 msdata: DataType 和 xs: type 类型不匹配,则可能发生数据损坏。Data corruption can occur if the msdata:DataType and the xs:type types do not match. 不会引发异常。No exception will be thrown.

通常调用 ReadXmlSchema 方法,然后调用用于填充 DataSetReadXml 方法。The ReadXmlSchema method is generally invoked before invoking the ReadXml method which is used to fill the DataSet.

派生自 Stream 类的类包括 BufferedStreamFileStreamMemoryStreamNetworkStreamClasses that derive from the Stream class include BufferedStream, FileStream, MemoryStream, and NetworkStream.

备注

如果你的 DataSet 的架构包含相同命名空间中具有相同名称但类型不同的元素,则当你尝试使用 ReadXmlSchema将架构读入 DataSet 时,将引发异常。If the schema for your DataSet contains elements of the same name, but different type, in the same namespace, an exception is be thrown when you attempt to read the schema into the DataSet with ReadXmlSchema. 如果使用 .NET Framework 版本1.0,则不会发生此异常。This exception does not occur if you are using .NET Framework version 1.0.

另请参阅

ReadXmlSchema(TextReader)

从指定的 TextReader 中将 XML 架构读入 DataSetReads the XML schema from the specified TextReader into the DataSet.

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

从中读取的 TextReaderThe TextReader from which to read.

示例

下面的示例创建一个 StreamReader 对象以便使用来读取架构,并使用对象调用 ReadXmlSchema 方法。The following example creates a StreamReader object to read a schema with, and invokes the ReadXmlSchema method with the object.

private void ReadSchemaFromStreamReader()
{
    // Create the DataSet to read the schema into.
    DataSet thisDataSet = new DataSet();

    // Set the file path and name. Modify this for your purposes.
    string filename="Schema.xml";

    // Create a StreamReader object with the file path and name.
    System.IO.StreamReader readStream = 
        new System.IO.StreamReader(filename);

    // Invoke the ReadXmlSchema method with the StreamReader object.
    thisDataSet.ReadXmlSchema(readStream);

    // Close the StreamReader
    readStream.Close();
}
Private Sub ReadSchemaFromStreamReader()
    ' Create the DataSet to read the schema into.
    Dim thisDataSet As New DataSet()

    ' Set the file path and name. Modify this for your purposes.
    Dim filename As String = "Schema.xml"

    ' Create a StreamReader object with the file path and name.
    Dim readStream As New System.IO.StreamReader(filename)

    ' Invoke the ReadXmlSchema method with the StreamReader object.
    thisDataSet.ReadXmlSchema(readStream)

    ' Close the StreamReader
    readStream.Close()
End Sub

注解

使用 ReadXmlSchema 方法为 DataSet创建架构。Use the ReadXmlSchema method to create the schema for a DataSet. 此架构包括表、关系和约束定义。The schema includes table, relation, and constraint definitions. 若要将架构写入 XML 文档,请使用 WriteXmlSchema 方法。To write a schema to an XML document, use the WriteXmlSchema method.

使用 XSD 标准编写 XML 架构。The XML schema is written using the XSD standard.

备注

如果 msdata: DataType 和 xs: type 类型不匹配,则可能发生数据损坏。Data corruption can occur if the msdata:DataType and the xs:type types do not match. 不会引发异常。No exception will be thrown.

通常调用 ReadXmlSchema 方法,然后调用用于填充 DataSetReadXml 方法。The ReadXmlSchema method is generally invoked before invoking the ReadXml method which is used to fill the DataSet.

继承自 TextReader 类的类包括 StreamReaderStringReader 类。Classes that inherit from the TextReader class include the StreamReader and StringReader classes.

备注

如果你的 DataSet 的架构包含相同命名空间中具有相同名称但类型不同的元素,则当你尝试使用 ReadXmlSchema将架构读入 DataSet 时,将引发异常。If the schema for your DataSet contains elements of the same name, but different type, in the same namespace, an exception is be thrown when you attempt to read the schema into the DataSet with ReadXmlSchema. 如果使用 .NET Framework 版本1.0,则不会发生此异常。This exception does not occur if you are using .NET Framework version 1.0.

另请参阅

ReadXmlSchema(String)

从指定的文件中将 XML 架构读入 DataSetReads the XML schema from the specified file into the DataSet.

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

参数

fileName
String

从中读取的文件的名称(包括路径)。The file name (including the path) from which to read.

异常

示例

private void ReadSchemaFromFile(){
   // Create the DataSet to read the schema into.
   DataSet thisDataSet = new DataSet();

   // Set the file path and name. Modify this for your purposes.
   string filename="Schema.xml";

   // Invoke the ReadXmlSchema method with the file name.
   thisDataSet.ReadXmlSchema(filename);
}
Private Sub ReadSchemaFromFile()
    ' Create the DataSet to read the schema into.
    Dim thisDataSet As New DataSet()

    ' Set the file path and name. Modify this for your purposes.
    Dim filename As String = "Schema.xml"

    ' Invoke the ReadXmlSchema method with the file name.
    thisDataSet.ReadXmlSchema(filename)
End Sub

注解

使用 ReadXmlSchema 方法为 DataSet创建架构。Use the ReadXmlSchema method to create the schema for a DataSet. 此架构包括表、关系和约束定义。The schema includes table, relation, and constraint definitions. 若要将架构写入 XML 文档,请使用 WriteXmlSchema 方法。To write a schema to an XML document, use the WriteXmlSchema method.

使用 XSD 标准编写 XML 架构。The XML schema is written using the XSD standard.

备注

如果 msdata: DataType 和 xs: type 类型不匹配,则可能发生数据损坏。Data corruption can occur if the msdata:DataType and the xs:type types do not match. 不会引发异常。No exception will be thrown.

通常调用 ReadXmlSchema 方法,然后调用用于填充 DataSetReadXml 方法。The ReadXmlSchema method is generally invoked before invoking the ReadXml method which is used to fill the DataSet.

备注

如果 DataSet 的架构在相同的命名空间中包含名称相同但类型不同的元素,则当您尝试使用 DataSet 将架构读入 ReadXmlSchema 中时将引发异常。If the schema for your DataSet contains elements of the same name, but different type, in the same namespace, an exception is thrown when you attempt to read the schema into the DataSet with ReadXmlSchema. 如果使用 .NET Framework 版本1.0,则不会发生此异常。This exception does not occur if you are using .NET Framework version 1.0.

另请参阅

ReadXmlSchema(XmlReader)

从指定的 XmlReader 中将 XML 架构读入 DataSetReads the XML schema from the specified XmlReader into the DataSet.

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

从中读取的 XmlReaderThe XmlReader from which to read.

示例

下面的示例创建一个新的 DataSetSystem.IO.FileStream 的对象。The following example creates a new DataSet and System.IO.FileStream object. 使用文件路径和文件名创建的 FileStream 对象用于创建作为参数传递给 ReadXmlSchema 方法的 System.Xml.XmlTextReaderThe FileStream object, created with a file path and file name, is used to create an System.Xml.XmlTextReader that is passed as an argument to the ReadXmlSchema method.

private void ReadSchemaFromXmlTextReader()
{
    // Create the DataSet to read the schema into.
    DataSet thisDataSet = new DataSet();

    // Set the file path and name. Modify this for your purposes.
    string filename="Schema.xml";

    // Create a FileStream object with the file path and name.
    System.IO.FileStream stream = new System.IO.FileStream
        (filename,System.IO.FileMode.Open);

    // Create a new XmlTextReader object with the FileStream.
    System.Xml.XmlTextReader xmlReader= 
        new System.Xml.XmlTextReader(stream);

    // Read the schema into the DataSet and close the reader.
    thisDataSet.ReadXmlSchema(xmlReader);
    xmlReader.Close();
}
Private Sub ReadSchemaFromXmlTextReader()
    ' Create the DataSet to read the schema into.
    Dim thisDataSet As New DataSet()

    ' Set the file path and name. Modify this for your purposes.
    Dim filename As String = "Schema.xml"

    ' Create a FileStream object with the file path and name.
    Dim stream As New System.IO.FileStream _
       (filename, System.IO.FileMode.Open)

    ' Create a new XmlTextReader object with the FileStream.
    Dim xmlReader As New System.Xml.XmlTextReader(stream)

    ' Read the schema into the DataSet and close the reader.
    thisDataSet.ReadXmlSchema(xmlReader)
    xmlReader.Close()
End Sub

注解

使用 ReadXmlSchema 方法为 DataSet创建架构。Use the ReadXmlSchema method to create the schema for a DataSet. 此架构包括表、关系和约束定义。The schema includes table, relation, and constraint definitions.

使用 XSD 标准编写 XML 架构。The XML schema is written using the XSD standard.

备注

如果 msdata: DataType 和 xs: type 类型不匹配,则可能发生数据损坏。Data corruption can occur if the msdata:DataType and the xs:type types do not match. 不会引发异常。No exception will be thrown.

通常调用 ReadXmlSchema 方法,然后调用用于填充 DataSetReadXml 方法。The ReadXmlSchema method is generally invoked before invoking the ReadXml method which is used to fill the DataSet.

System.Xml.XmlReader 类是抽象类。The System.Xml.XmlReader class is abstract. 继承自的类是 System.Xml.XmlTextReaderXmlReaderA class that inherits from the XmlReader is the System.Xml.XmlTextReader class.

备注

如果你的 DataSet 的架构包含相同命名空间中具有相同名称但类型不同的元素,则当你尝试使用 ReadXmlSchema将架构读入 DataSet 时,将引发异常。If the schema for your DataSet contains elements of the same name, but different type, in the same namespace, an exception is be thrown when you attempt to read the schema into the DataSet with ReadXmlSchema. 如果使用 .NET Framework 版本1.0,则不会发生此异常。This exception does not occur if you are using .NET Framework version 1.0.

另请参阅

适用于