Export (0) Print
Expand All

DataSet.WriteXmlSchema Method (XmlWriter)

.NET Framework 1.1

Writes the DataSet structure as an XML schema to an XmlWriter object.

[Visual Basic]
Overloads Public Sub WriteXmlSchema( _
   ByVal writer As XmlWriter _
)
[C#]
public void WriteXmlSchema(
 XmlWriter writer
);
[C++]
public: void WriteXmlSchema(
 XmlWriter* writer
);
[JScript]
public function WriteXmlSchema(
   writer : XmlWriter
);

Parameters

writer
The XmlWriter with which to write.

Remarks

Use the WriteXmlSchema method to write the schema for a DataSet to an XML document. The schema includes table, relation, and constraint definitions. To write a schema to an XML document, use the WriteXmlSchema method.

The XML schema is written using the XSD standard.

To write the data to an XML document, use the WriteXml method.

One class that inherits from the System.Xml.XmlWriter class is the System.Xml.XmlTextWriter class.

Example

[Visual Basic, C#, C++] The following example creates a new System.IO.FileStream object with the specified path. The FileStream object is used to create an System.Xml.XMLTextWriter object. The WriteXmlSchema method is then invoked with the XmlTextWriter object to write the schema to the disk.

[Visual Basic] 
Private Sub WriteSchemaWithXmlTextWriter(thisDataSet As 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.Create)
    ' Create a new XmlTextWriter object with the FileStream.
    Dim MyXmlTextWriter As New System.Xml.XmlTextWriter _
       (myFileStream, System.Text.Encoding.Unicode)
    ' Write the schema into the DataSet and close the reader.
    thisDataSet.WriteXmlSchema(MyXmlTextWriter)
    MyXmlTextWriter.Close()
End Sub

[C#] 
private void WriteSchemaWithXmlTextWriter(DataSet thisDataSet){
   // 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.Create);
   // Create a new XmlTextWriter object with the FileStream.
   System.Xml.XmlTextWriter MyXmlTextWriter = 
      new System.Xml.XmlTextWriter(myFileStream, System.Text.Encoding.Unicode);
   // Write the schema into the DataSet and close the reader.
   thisDataSet.WriteXmlSchema(MyXmlTextWriter );
   MyXmlTextWriter.Close();
}

[C++] 
private:
 void WriteSchemaWithXmlTextWriter(DataSet* thisDataSet){
    // 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::Create);
    // Create a new XmlTextWriter object with the FileStream.
    System::Xml::XmlTextWriter* MyXmlTextWriter = 
       new System::Xml::XmlTextWriter(myFileStream, System::Text::Encoding::Unicode);
    // Write the schema into the DataSet and close the reader.
    thisDataSet->WriteXmlSchema(MyXmlTextWriter );
    MyXmlTextWriter->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.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

DataSet Class | DataSet Members | System.Data Namespace | DataSet.WriteXmlSchema Overload List | ReadXml | ReadXmlSchema | WriteXml

Show:
© 2014 Microsoft