DataSet.ReadXmlSchema 方法

定义

将 XML 架构读入 DataSet

重载

ReadXmlSchema(Stream)

从指定的 Stream 中将 XML 架构读入 DataSet

ReadXmlSchema(TextReader)

从指定的 TextReader 中将 XML 架构读入 DataSet

ReadXmlSchema(String)

从指定的文件中将 XML 架构读入 DataSet

ReadXmlSchema(XmlReader)

从指定的 XmlReader 中将 XML 架构读入 DataSet

ReadXmlSchema(Stream)

从指定的 Stream 中将 XML 架构读入 DataSet

public:
 void ReadXmlSchema(System::IO::Stream ^ stream);
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

从中读取的 Stream

示例

以下示例创建一个 FileStream 对象来读取 XML 架构,并使用该对象调用 ReadXmlSchema 该方法。

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 架构包括表、关系和约束定义。 若要将架构写入 XML 文档,请使用 WriteXmlSchema 该方法。

XML 架构是使用 XSD 标准编写的。

备注

如果 msdata:DataType 和 xs:type 类型不匹配,则会发生数据损坏。 不会引发异常。

ReadXmlSchema 调用 ReadXml 用于填充 DataSet的方法之前,通常会调用该方法。

派生自类的Stream类包括BufferedStreamFileStreamMemoryStreamNetworkStream

备注

如果架构 DataSet 包含同名元素,但类型不同,在同一命名空间中,尝试将架构读取到 DataSet 其中 ReadXmlSchema时,将引发异常。 如果使用 .NET Framework 版本 1.0,则不会发生此异常。

另请参阅

适用于

ReadXmlSchema(TextReader)

从指定的 TextReader 中将 XML 架构读入 DataSet

public:
 void ReadXmlSchema(System::IO::TextReader ^ reader);
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

示例

以下示例创建一个 StreamReader 对象来读取架构,并使用该对象调用 ReadXmlSchema 该方法。

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 架构包括表、关系和约束定义。 若要将架构写入 XML 文档,请使用 WriteXmlSchema 该方法。

XML 架构是使用 XSD 标准编写的。

备注

如果 msdata:DataType 和 xs:type 类型不匹配,则会发生数据损坏。 不会引发异常。

ReadXmlSchema 调用 ReadXml 用于填充 DataSet的方法之前,通常会调用该方法。

从类继承的 TextReader 类包括 StreamReaderStringReader 类。

备注

如果架构 DataSet 包含同名元素,但类型不同,在同一命名空间中,尝试将架构读取到 DataSet 其中 ReadXmlSchema时,将引发异常。 如果使用 .NET Framework 版本 1.0,则不会发生此异常。

另请参阅

适用于

ReadXmlSchema(String)

从指定的文件中将 XML 架构读入 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

从中读取的文件的名称(包括路径)。

例外

示例

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 架构包括表、关系和约束定义。 若要将架构写入 XML 文档,请使用 WriteXmlSchema 该方法。

XML 架构是使用 XSD 标准编写的。

备注

如果 msdata:DataType 和 xs:type 类型不匹配,则会发生数据损坏。 不会引发异常。

ReadXmlSchema 调用 ReadXml 用于填充 DataSet的方法之前,通常会调用该方法。

备注

如果 DataSet 的架构在相同的命名空间中包含名称相同但类型不同的元素,则当您尝试使用 DataSet 将架构读入 ReadXmlSchema 中时将引发异常。 如果使用 .NET Framework 版本 1.0,则不会发生此异常。

另请参阅

适用于

ReadXmlSchema(XmlReader)

从指定的 XmlReader 中将 XML 架构读入 DataSet

public:
 void ReadXmlSchema(System::Xml::XmlReader ^ reader);
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

示例

以下示例创建一个新 DataSet 对象和 System.IO.FileStream 对象。 使用 FileStream 文件路径和文件名创建的对象用于创建 System.Xml.XmlTextReader 作为参数传递给方法的对象 ReadXmlSchema

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 架构包括表、关系和约束定义。

XML 架构是使用 XSD 标准编写的。

备注

如果 msdata:DataType 和 xs:type 类型不匹配,则会发生数据损坏。 不会引发异常。

ReadXmlSchema 调用 ReadXml 用于填充 DataSet的方法之前,通常会调用该方法。

类是抽象的 System.Xml.XmlReader 。 继承自类的XmlReaderSystem.Xml.XmlTextReader类。

备注

如果架构 DataSet 包含同名元素,但类型不同,在同一命名空间中,尝试将架构读取到 DataSet 其中 ReadXmlSchema时,将引发异常。 如果使用 .NET Framework 版本 1.0,则不会发生此异常。

另请参阅

适用于