DataTable::WriteXmlSchema Method
Writes the current data structure of the DataTable as an XML schema.
Assembly: System.Data (in System.Data.dll)
| Name | Description | |
|---|---|---|
![]() | WriteXmlSchema(Stream^) | Writes the current data structure of the DataTable as an XML schema to the specified stream. |
![]() | WriteXmlSchema(Stream^, Boolean) | Writes the current data structure of the DataTable as an XML schema to the specified stream. To save the schema for the table and all its descendants, set the writeHierarchy parameter to true. |
![]() | WriteXmlSchema(String^) | Writes the current data structure of the DataTable as an XML schema to the specified file. |
![]() | WriteXmlSchema(String^, Boolean) | Writes the current data structure of the DataTable as an XML schema to the specified file. To save the schema for the table and all its descendants, set the writeHierarchy parameter to true. |
![]() | WriteXmlSchema(TextWriter^) | Writes the current data structure of the DataTable as an XML schema using the specified TextWriter. |
![]() | WriteXmlSchema(TextWriter^, Boolean) | Writes the current data structure of the DataTable as an XML schema using the specified TextWriter. To save the schema for the table and all its descendants, set the writeHierarchy parameter to true. |
![]() | WriteXmlSchema(XmlWriter^) | |
![]() | WriteXmlSchema(XmlWriter^, Boolean) |
The following console application creates two DataTable instances, adds each to a DataSet, creates a DataRelation relating the two tables, and then uses the WriteXmlSchema method to write the data contained within the parent table to a TextWriter. The example demonstrates the behavior when setting the writeHierarchy parameter to each of its values.
Note |
|---|
This example shows how to use one of the overloaded versions of WriteXmlSchema For other examples that might be available, see the individual overload topics. |
The example displays the following output in the console window:
==============================
Customer table, without hierarchy
==============================
<?xml version="1.0" encoding="utf-16"?>
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:MainDataTable="Ta
ble1">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="Table1">
<xs:complexType>
<xs:sequence>
<xs:element name="ID" type="xs:int" />
<xs:element name="Name" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
<xs:unique name="Constraint1" msdata:PrimaryKey="true">
<xs:selector xpath=".//Table1" />
<xs:field xpath="ID" />
</xs:unique>
</xs:element>
</xs:schema>
==============================
Customer table, with hierarchy
==============================
<?xml version="1.0" encoding="utf-16"?>
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:MainDataTable="Table1">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="Table1">
<xs:complexType>
<xs:sequence>
<xs:element name="ID" type="xs:int" />
<xs:element name="Name" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Table2">
<xs:complexType>
<xs:sequence>
<xs:element name="OrderID" type="xs:int" />
<xs:element name="CustomerID" type="xs:int" minOccurs="0" />
<xs:element name="OrderDate" type="xs:dateTime" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
<xs:unique name="Constraint1" msdata:PrimaryKey="true">
<xs:selector xpath=".//Table1" />
<xs:field xpath="ID" />
</xs:unique>
<xs:unique name="Table2_Constraint1" msdata:ConstraintName="Constraint1" msdata:PrimaryKey="true">
<xs:selector xpath=".//Table2" />
<xs:field xpath="OrderID" />
</xs:unique>
<xs:keyref name="CustomerOrder" refer="Constraint1">
<xs:selector xpath=".//Table2" />
<xs:field xpath="CustomerID" />
</xs:keyref>
</xs:element>
</xs:schema>

