Writing DataSet Schema Information as XSD (ADO.NET)
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 Typed DataSets (ADO.NET).
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 DataSet Contents as XML Data (ADO.NET).
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"); dataSet.WriteXmlSchema(writer); writer.Close();
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.