Compartilhar via


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.

dataSet.WriteXmlSchema("Customers.xsd")
dataSet.WriteXmlSchema("Customers.xsd");
Dim writer As System.IO.StreamWriter = New System.IO.StreamWriter("Customers.xsd")
dataSet.WriteXmlSchema(writer)
writer.Close()
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.

Dim schemaString As String = dataSet.GetXmlSchema()
string schemaString = dataSet.GetXmlSchema();

See Also

Concepts

Writing a DataSet as XML Data

Other Resources

Using XML in a DataSet
Working with a Typed DataSet
Using DataSets in ADO.NET