System.Data Namespace DataSet Class
Writes XML data, and optionally the schema, from the DataSet.
1. Writes the current data for a DataSet using the specified Stream.
2. Writes the current data for a DataSet using the specified file.
3. Writes the current data for a DataSet using the specified TextWriter.
4. Writes the current data for a DataSet using the specified XmlWriter.
5. Writes the current data, and optionally the schema, for a DataSet using the specified Stream and XmlWriteMode. To write the schema, set the value for the XmlWriteMode parameter to WriteSchema.
6. Writes the current data, and optionally the schema, for a DataSet using the specified file and XmlWriteMode. To write the schema, set the value for the XmlWriteMode parameter to WriteSchema.
7. Writes the current data, and optionally the schema, for a DataSet using the specified TextWriter and XmlWriteMode. To write the schema, set the value for the XmlWriteMode parameter to WriteSchema.
8. Writes the current data, and optionally the schema, for a DataSet using the specified XmlWriter and XmlWriteMode. To write the schema, set the value for the XmlWriteMode parameter to WriteSchema.
The following example initializes a System.IO.FileStream object that is used to create a new XmlTextWriter. The XmlTextWriter object is used with the WriteXml method to write an XML document.
NOTE: This example uses one of the overloaded versions of WriteXml. For other examples that may be available, see the individual overload topics.
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 ( );
}
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# |
VB |
DataSet Members WriteXmlSchema ReadXml ReadXmlSchema