Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.
3 out of 4 rated this helpful - Rate this topic

DataSet.WriteXml Method

Writes XML data, and optionally the schema, from the DataSet.

Overload List

Writes the current data for the DataSet using the specified System.IO.Stream.

[Visual Basic] Overloads Public Sub WriteXml(Stream)
[C#] public void WriteXml(Stream);
[C++] public: void WriteXml(Stream*);
[JScript] public function WriteXml(Stream);

Writes the current data for the DataSet to the specified file.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Sub WriteXml(String)
[C#] public void WriteXml(string);
[C++] public: void WriteXml(String*);
[JScript] public function WriteXml(String);

Writes the current data for the DataSet using the specified TextWriter.

[Visual Basic] Overloads Public Sub WriteXml(TextWriter)
[C#] public void WriteXml(TextWriter);
[C++] public: void WriteXml(TextWriter*);
[JScript] public function WriteXml(TextWriter);

Writes the current data for the DataSet to the specified XmlWriter.

[Visual Basic] Overloads Public Sub WriteXml(XmlWriter)
[C#] public void WriteXml(XmlWriter);
[C++] public: void WriteXml(XmlWriter*);
[JScript] public function WriteXml(XmlWriter);

Writes the current data, and optionally the schema, for the DataSet using the specified System.IO.Stream and XmlWriteMode. To write the schema, set the value for the XMLWriteMode parameter to WriteSchema.

[Visual Basic] Overloads Public Sub WriteXml(Stream, XmlWriteMode)
[C#] public void WriteXml(Stream, XmlWriteMode);
[C++] public: void WriteXml(Stream*, XmlWriteMode);
[JScript] public function WriteXml(Stream, XmlWriteMode);

Writes the current data, and optionally the schema, for the DataSet to the specified file using the specified XmlWriteMode. To write the schema, set the value for the XMLWriteMode parameter to WriteSchema.

[Visual Basic] Overloads Public Sub WriteXml(String, XmlWriteMode)
[C#] public void WriteXml(string, XmlWriteMode);
[C++] public: void WriteXml(String*, XmlWriteMode);
[JScript] public function WriteXml(String, XmlWriteMode);

Writes the current data, and optionally the schema, for the DataSet using the specified TextWriter and XmlWriteMode. To write the schema, set the value for the XMLWriteMode parameter to WriteSchema.

[Visual Basic] Overloads Public Sub WriteXml(TextWriter, XmlWriteMode)
[C#] public void WriteXml(TextWriter, XmlWriteMode);
[C++] public: void WriteXml(TextWriter*, XmlWriteMode);
[JScript] public function WriteXml(TextWriter, XmlWriteMode);

Writes the current data, and optionally the schema, for the DataSet using the specified XmlWriter and XmlWriteMode. To write the schema, set the value for the XMLWriteMode parameter to WriteSchema.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Sub WriteXml(XmlWriter, XmlWriteMode)
[C#] public void WriteXml(XmlWriter, XmlWriteMode);
[C++] public: void WriteXml(XmlWriter*, XmlWriteMode);
[JScript] public function WriteXml(XmlWriter, XmlWriteMode);

Example

[Visual Basic, C#, C++] The following example creates a System.IO.FileStream object that is used to create a new System.Xml.XmlTextWriter. The XmlTextWriter object is used with the WriteXml method to write an XML document.

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of WriteXml. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
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] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

DataSet Class | DataSet Members | System.Data Namespace

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.