You may experience some limitations when you use a
DataSet object to read a schema file that the
DataSet object did not create.
Unique Constraints
The
DataSet object only recognizes unique constraints if the unique element is located at the
DataSet element level. For example, in the following schema file, you do not see the unique constraint, although this is a valid XML Schema Definition (XSD).
<?xml version="1.0" encoding="utf-8" ?>
<xsd:schema id="configuration" targetNamespace="http://microsoft.com/test/XMLSchema1.xsd"
xmlns:x1="http://microsoft.com/test/XMLSchema1.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
attributeFormDefault="qualified" elementFormDefault="qualified">
<xsd:element name="configuration" msdata:IsDataSet="true" msdata:EnforceConstraints="true">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="document" minOccurs="1" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="parameter" minOccurs="0" maxOccurs="unbounded">
<xsd:complexType>
<xsd:attribute name="name" form="unqualified" type="xsd:string" use="required" />
<xsd:attribute name="value" form="unqualified" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:unique name="unique1">
<xsd:selector xpath="./x1:parameter" />
<xsd:field xpath="@name" />
</xsd:unique>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
The
DataSet object does recognize the unique element in the following schema file:
<?xml version="1.0" encoding="utf-8" ?>
<xsd:schema id="configuration" targetNamespace="http://microsoft.com/test/XMLSchema1.xsd"
xmlns:x1="http://microsoft.com/test/XMLSchema1.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
attributeFormDefault="qualified" elementFormDefault="qualified">
<xsd:element name="configuration" msdata:IsDataSet="true" msdata:EnforceConstraints="true">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="document" minOccurs="1" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="parameter" minOccurs="0" maxOccurs="unbounded">
<xsd:complexType>
<xsd:attribute name="name" form="unqualified" type="xsd:string" use="required" />
<xsd:attribute name="value" form="unqualified" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:unique name="unique1">
<xsd:selector xpath=".//x1:parameter" />
<xsd:field xpath="@name" />
</xsd:unique>
</xsd:element>
</xsd:schema>
Microsoft recommends that you use the
WriteXmlSchema method of the
DataSet object to create the schema files. This ensures that the
DataSet object can use the schema file and is in a format that the
DataSet object recognizes.
This behavior is by design.
Use of Restriction Element Is Mostly Ignored
You can derive a new simple type by restricting an existing simple type with the
restriction element. When you use the
restriction element in simple types, the
restriction element is ignored. Therefore, all the sub-elements of that
restriction element are ignored also.
For example:
<xsd:simpleType name="OrderID">
<xsd:restriction base="xsd:string">
<xsd:pattern value="\d{3}-[A-Z]{2}"/>
</xsd:restriction>
</xsd:simpleType>
All
restriction elements are ignored except the XSD simple type "string", and its facets as follows:
For more information about the DataSets and XSD, see the "Writing DataSet Schema Information as XML Schema (XSD)" topic at the following Microsoft Developer Network (MSDN):
NOTE: This information is also available in the Microsoft Visual Studio .NET Help documentation.