2.3.2 DataTable Element Schema

The DataInstance schema MUST define zero or more DataTable elements as children of the DataInstance element. A DataTable element MUST be defined using an anonymous complex type, and conform to the following rules:

  • A DataTable element complex type definition MUST NOT contain attribute definitions.

  • A DataTable element definition MUST allow only element content.

  • A DataTable element definition MUST define zero or more DataColumn element definitions that are the immediate children of the sequence.

  • The content model of a DataTable element definition MUST be specified as a sequence of elements, referred to as DataColumn elements, each of which represents a column in the table.

    • The type of a DataColumn element definition MUST be specified as one of the following valid http://www.w3.org/2001/XMLSchema:types. If the type is a string, the type can be a simple type restriction of the facets as defined by [XMLSCHEMA2] section 3.2.1.1, length, minlength, and maxlength. All other types MUST NOT be restricted.

      • string

      • Boolean

      • unsignedByte

      • base64Binary

      • double

      • float

      • short

      • int

      • long

      • byte

      • integer

      • decimal

      • date

      • time

      • unsignedShort

      • unsignedInt

      • unsignedLong

      • dateTime

    • The minimum occurrence of a DataColumn element definition MUST be zero or one and the maximum occurrence MUST be one.

    • If the type of the DataColumn element definition is a string, then all data in the DataColumn instance MUST be interpreted as CDATA section, even if it contains data that could be interpreted as XML.

    • Each extended property MUST appear as an attribute in the declaration of the DataColumn element (for properties that apply to columns). The attribute name MUST be the name of the extended property and the attribute’s namespace MUST be urn:schemas-microsoft-com:xml-msprop. The attribute’s value MUST be the value of the extended property.

    • Any attributes with a namespace other than urn:schemas-microsoft-com:xml-msprop are not extended properties.

  • Each extended property MUST appear as an attribute in the declaration of the DataTable element (for properties that apply to tables). The attribute name MUST be the name of the extended property and the attribute’s namespace MUST be urn:schemas-microsoft-com:xml-msprop. The attribute’s value MUST be the value of the extended property.

  • Any attributes with a namespace other than urn:schemas-microsoft-com:xml-msprop are not extended properties.

The following is a sample Schema element from a DiffGram:

  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
 xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" 
 xmlns:msprop="urn:schemas-microsoft-com:xml-msprop">
      <xs:element name="SalesDS" msdata:IsDataSet="true">
        <xs:complexType>
          <xs:choice minOccurs="0" maxOccurs="unbounded">
            <xs:element name="Customers" msprop:ExtProp1="USA">
              <xs:complexType>
                <xs:sequence>
                  <xs:element name="CustId" type="xs:int" minOccurs="0"/>
                  <xs:element name="CustName" type="xs:string" minOccurs="0"/>
                </xs:sequence>
              </xs:complexType>
            </xs:element>
          </xs:choice>
        </xs:complexType>
         <xs:unique name="Constraint2" msdata:PrimaryKey="true">
              <xs:selector xpath=".//Customers" />
              <xs:field xpath="CustId" />
         </xs:unique>
       </xs:element>
  </xs:schema>

In this sample, the element SalesDS defines the DataInstance element. It can contain Customers elements, which are known as DataTable elements, corresponding to rows in the Customers table in the DataSet. The columns of the Customers table (CustId and CustName), which are known as DataColumn elements, are represented as child elements of the Customers element. The primary key of the DataTable element is specified in the Unique element. The selector defines which DataTable element to reference. The field element defines what DataColumn element is part of the primary key. An extended property on the Customers table, ExtProp1 is manifested as an attribute on the Customers DataTable element declaration.