次の方法で共有


DataSet.WriteXml メソッド (XmlWriter, XmlWriteMode)

指定した XmlWriterXmlWriteMode を使用して、 DataSet の現在のデータを書き込みます。オプションでスキーマを書き込むこともできます。スキーマを書き込むには、 XMLWriteMode パラメータの値を WriteSchema に設定します。

Overloads Public Sub WriteXml( _
   ByVal writer As XmlWriter, _   ByVal mode As XmlWriteMode _)
[C#]
public void WriteXml(XmlWriterwriter,XmlWriteModemode);
[C++]
public: void WriteXml(XmlWriter* writer,XmlWriteModemode);
[JScript]
public function WriteXml(
   writer : XmlWriter,mode : XmlWriteMode);

パラメータ

解説

WriteXml メソッドを使用すると、 DataSet から XML ドキュメントに、データだけ、またはデータとスキーマの両方を書き込むことができます。これに対して、 WriteXmlSchema メソッドは、スキーマだけを書き込みます。データとスキーマの両方を書き込むには、 WriteXmlMode パラメータを WriteSchema に設定します。

それぞれ ReadXml メソッドと ReadXmlSchema メソッドでも同様です。XML データ、またはスキーマとデータの両方を DataSet に読み込むには、 ReadXml メソッドを使用します。スキーマだけを読み込むには、 ReadXmlSchema メソッドを使用します。

使用例

[Visual Basic, C#, C++] 新しい System.Xml.XmlTextWriter の作成に使用される System.IO.FileStream オブジェクトを作成する例を次に示します。 WriteXml メソッドで XmlTextWriter オブジェクトを使用して、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)
    ' Create an XmlTextWriter with the fileStream.
    Dim myXmlWriter As New System.Xml.XmlTextWriter _
       (myFileStream, System.Text.Encoding.Unicode)
    ' Write to the file with the WriteXml method.
    thisDataSet.WriteXml(myXmlWriter)
    myXmlWriter.Close()
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);
    // Create an XmlTextWriter with the fileStream.
    System.Xml.XmlTextWriter myXmlWriter = 
       new System.Xml.XmlTextWriter(myFileStream, System.Text.Encoding.Unicode);
    // Write to the file with the WriteXml method.
    thisDataSet.WriteXml(myXmlWriter);   
    myXmlWriter.Close();
 }

[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);
    // Create an XmlTextWriter with the fileStream.
    System::Xml::XmlTextWriter* myXmlWriter = 
       new System::Xml::XmlTextWriter(myFileStream, System::Text::Encoding::Unicode);
    // Write to the file with the WriteXml method.
    thisDataSet->WriteXml(myXmlWriter);   
    myXmlWriter->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.WriteXml オーバーロードの一覧 | ReadXml | ReadXmlSchema | WriteXml | WriteXmlSchema