This documentation is archived and is not being maintained.

Writing DataSet Schema Information as XML Schema (XSD) 

You can write the schema of a DataSet as XML Schema definition language (XSD) schema, so that you can transport it, with or without related data, in an XML document. XML Schema can be written to a file, a stream, an XmlWriter, or a string; it is useful for generating a strongly typed DataSet. For more information about strongly typed DataSet objects, see Working with a Typed DataSet.

You can specify how a column of a table is represented in XML Schema using the ColumnMapping property of the DataColumn object. For more information, see "Mapping Columns to XML Elements, Attributes, and Text" in Writing a DataSet as XML Data.

To write the schema of a DataSet as XML Schema, to a file, stream, or XmlWriter, use the WriteXmlSchema method of the DataSet. WriteXmlSchema takes one parameter that specifies the destination of the resulting XML Schema. The following code examples demonstrate how to write the XML Schema of a DataSet to a file by passing a string containing a file name and a StreamWriter object.

System.IO.StreamWriter writer = new System.IO.StreamWriter("Customers.xsd");

To obtain the schema of a DataSet and write it as an XML Schema string, use the GetXmlSchema method, as shown in the following example.

string schemaString = dataSet.GetXmlSchema();

See Also