DataTable::WriteXmlSchema Method

 

Writes the current data structure of the DataTable as an XML schema.

Namespace:   System.Data
Assembly:  System.Data (in System.Data.dll)

NameDescription
System_CAPS_pubmethodWriteXmlSchema(Stream^)

Writes the current data structure of the DataTable as an XML schema to the specified stream.

System_CAPS_pubmethodWriteXmlSchema(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.

System_CAPS_pubmethodWriteXmlSchema(String^)

Writes the current data structure of the DataTable as an XML schema to the specified file.

System_CAPS_pubmethodWriteXmlSchema(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.

System_CAPS_pubmethodWriteXmlSchema(TextWriter^)

Writes the current data structure of the DataTable as an XML schema using the specified TextWriter.

System_CAPS_pubmethodWriteXmlSchema(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.

System_CAPS_pubmethodWriteXmlSchema(XmlWriter^)

Writes the current data structure of the DataTable as an XML schema using the specified XmlWriter.

System_CAPS_pubmethodWriteXmlSchema(XmlWriter^, Boolean)

Writes the current data structure of the DataTable as an XML schema using the specified XmlWriter. To save the schema for the table and all its descendants, set the writeHierarchy parameter to true.

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

The XML schema is written using the XSD standard.

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

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.

System_CAPS_noteNote

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.

No code example is currently available or this language may not be supported.

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>
Return to top
Show: