DataSet.ReadXmlSchema DataSet.ReadXmlSchema DataSet.ReadXmlSchema DataSet.ReadXmlSchema Method

定义

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

重载

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

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

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

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

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

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

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

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

ReadXmlSchema(Stream) ReadXmlSchema(Stream) 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 Stream 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

注解

使用方法创建的架构DataSetReadXmlSchemaUse 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在调用用于DataSet填充的方法之前调用方法。ReadXmlThe 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中包含同名但类型不同的元素的架构,则在您尝试DataSet使用ReadXmlSchema将架构读入时,将引发异常。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) ReadXmlSchema(TextReader) ReadXmlSchema(TextReader) 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 TextReader TextReader 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

注解

使用方法创建的架构DataSetReadXmlSchemaUse 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在调用用于DataSet填充的方法之前调用方法。ReadXmlThe ReadXmlSchema method is generally invoked before invoking the ReadXml method which is used to fill the DataSet.

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

备注

如果在同一命名空间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 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) ReadXmlSchema(String) ReadXmlSchema(String) 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 String String 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

注解

使用方法创建的架构DataSetReadXmlSchemaUse 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在调用用于DataSet填充的方法之前调用方法。ReadXmlThe 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.

安全性

FileIOPermission
用于读取和写入文件。for reading and writing files. 关联的枚举:FileIOPermissionAccessAssociated enumeration: FileIOPermissionAccess

另请参阅

ReadXmlSchema(XmlReader) ReadXmlSchema(XmlReader) ReadXmlSchema(XmlReader) 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 XmlReader XmlReader XmlReader

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

示例

下面的示例创建一个新DataSetSystem.IO.FileStream和一个对象。The following example creates a new DataSet and System.IO.FileStream object. 使用文件路径和文件名创建的System.Xml.XmlTextReader ReadXmlSchema FileStream对象用于创建一个作为参数传递给方法的。The 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

注解

使用方法创建的架构DataSetReadXmlSchemaUse 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在调用用于DataSet填充的方法之前调用方法。ReadXmlThe 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. 继承自的XmlReaderSystem.Xml.XmlTextReader是类。A class that inherits from the XmlReader is the System.Xml.XmlTextReader class.

备注

如果在同一命名空间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 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.

另请参阅

适用于