指定した System.IO.Stream を使用して DataSet の現在のデータを書き込みます。
Overloads Public Sub WriteXml( _
ByVal stream As Stream _)
[C#]
public void WriteXml(Streamstream);
[C++]
public: void WriteXml(Stream* stream);
[JScript]
public function WriteXml(
stream : Stream);
パラメータ
- stream
ファイルに書き込むために使用する Stream オブジェクト。
解説
WriteXml メソッドを使用すると、 DataSet から XML ドキュメントに、データだけ、またはデータとスキーマの両方を書き込むことができます。これに対して、 WriteXmlSchema メソッドは、スキーマだけを書き込みます。データとスキーマの両方を書き込むには、 WriteXmlMode パラメータを含んだオーバーロードの 1 つを使用し、その値を WriteSchema に設定します。
それぞれ ReadXml メソッドと ReadXmlSchema メソッドでも同様です。XML データ、またはスキーマとデータの両方を DataSet に読み込むには、 ReadXml メソッドを使用します。スキーマだけを読み込むには、 ReadXmlSchema メソッドを使用します。
使用例
[Visual Basic, C#, C++] System.IO.FileStream オブジェクトを作成する例を次に示します。 WriteXml メソッドでオブジェクトを使用して、XML ドキュメントを書き込みます。
Private Sub WriteXmlToFile(thisDataSet As DataSet)
If thisDataSet Is Nothing Then
Return
End If ' Create a file name to write to.
Dim filename As String = "myXmlDoc.xml"
' Create the FileStream to write with.
Dim myFileStream As New System.IO.FileStream _
(filename, System.IO.FileMode.Create)
' Write to the file with the WriteXml method.
thisDataSet.WriteXml(myFileStream)
End Sub
[C#]
private void WriteXmlToFile(DataSet thisDataSet) {
if (thisDataSet == null) { return; }
// Create a file name to write to.
string filename = "myXmlDoc.xml";
// Create the FileStream to write with.
System.IO.FileStream myFileStream = new System.IO.FileStream
(filename, System.IO.FileMode.Create);
// Write to the file with the WriteXml method.
thisDataSet.WriteXml(myFileStream);
}
[C++]
private:
void WriteXmlToFile(DataSet* thisDataSet) {
if (thisDataSet == 0) { return; }
// Create a file name to write to.
String* filename = S"myXmlDoc.xml";
// Create the FileStream to write with.
System::IO::FileStream* myFileStream = new System::IO::FileStream
(filename, System::IO::FileMode::Create);
// Write to the file with the WriteXml method.
thisDataSet->WriteXml(myFileStream);
}
[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 ファミリ
参照
DataSet クラス | DataSet メンバ | System.Data 名前空間 | DataSet.WriteXml オーバーロードの一覧 | ReadXml | ReadXmlSchema | WriteXml | WriteXmlSchema