指定した XmlReader から DataSet に XML スキーマを読み込みます。
Overloads Public Sub ReadXmlSchema( _
ByVal reader As XmlReader _)
[C#]
public void ReadXmlSchema(XmlReaderreader);
[C++]
public: void ReadXmlSchema(XmlReader* reader);
[JScript]
public function ReadXmlSchema(
reader : XmlReader);
パラメータ
- reader
読み込み元の XmlReader 。
解説
ReadXmlSchema メソッドを使用して、 DataSet のスキーマを作成します。スキーマにはテーブル、リレーションシップ、制約の各定義が含まれています。
XML スキーマの書き込みには、XSD 標準を使用します。
通常、 ReadXmlSchema メソッドは、 DataSet への格納に使用する ReadXml メソッドの呼び出しの前に呼び出されます。
System.Xml.XmlReader クラスは抽象クラスです。XmlReader から継承するクラスは System.Xml.XmlTextReader クラスです。
メモ DataSet のスキーマに、同じ名前空間で名前が同じであるが型が違う要素が含まれている場合、スキーマを ReadXmlSchema で DataSet に読み込もうとすると、例外がスローされます。この例外は、.NET Framework Version 1.0 を使用している場合は発生しません。
使用例
[Visual Basic, C#, C++] 新しい DataSet および System.IO.FileStream オブジェクトを作成する例を次に示します。ファイル パスとファイル名で作成した FileStream オブジェクトを使用して、引数として ReadXmlSchema メソッドに渡される System.Xml.XmlTextReader を作成します。
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 = "mySchema.xml"
' Create a FileStream object with the file path and name.
Dim myFileStream As New System.IO.FileStream _
(filename, System.IO.FileMode.Open)
' Create a new XmlTextReader object with the FileStream.
Dim myXmlTextReader As New System.Xml.XmlTextReader(myFileStream)
' Read the schema into the DataSet and close the reader.
thisDataSet.ReadXmlSchema(myXmlTextReader)
myXmlTextReader.Close()
End Sub
[C#]
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="mySchema.xml";
// Create a FileStream object with the file path and name.
System.IO.FileStream myFileStream = new System.IO.FileStream
(filename,System.IO.FileMode.Open);
// Create a new XmlTextReader object with the FileStream.
System.Xml.XmlTextReader myXmlTextReader=
new System.Xml.XmlTextReader(myFileStream);
// Read the schema into the DataSet and close the reader.
thisDataSet.ReadXmlSchema(myXmlTextReader);
myXmlTextReader.Close();
}
[C++]
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=S"mySchema.xml";
// Create a FileStream object with the file path and name.
System::IO::FileStream* myFileStream = new System::IO::FileStream
(filename,System::IO::FileMode::Open);
// Create a new XmlTextReader object with the FileStream.
System::Xml::XmlTextReader* myXmlTextReader=
new System::Xml::XmlTextReader(myFileStream);
// Read the schema into the DataSet and close the reader.
thisDataSet->ReadXmlSchema(myXmlTextReader);
myXmlTextReader->Close();
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET
参照
DataSet クラス | DataSet メンバ | System.Data 名前空間 | DataSet.ReadXmlSchema オーバーロードの一覧 | ReadXml | WriteXml