Article ID: 319372 - Last Review: October 29, 2002 - Revision: 1.2

PRB: Limitations for DataSet Schema Files (XSD)

System TipThis article applies to a different operating system than the one you are using. Article content that may not be relevant to you is disabled.
This article was previously published under Q319372

On This Page

Expand all | Collapse all

SYMPTOMS

You may experience some limitations when you use a DataSet object to read a schema file that the DataSet object did not create.

CAUSE

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>


				

RESOLUTION

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.

STATUS

This behavior is by design.

MORE INFORMATION

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:
  • length
  • minlength
  • maxlength

REFERENCES

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):
Writing DataSet Schema Information as XML Schema (XSD) (http://msdn.microsoft.com/en-us/library/aa735743.aspx)
NOTE: This information is also available in the Microsoft Visual Studio .NET Help documentation.

APPLIES TO
  • Microsoft Visual Studio .NET 2002 Professional Edition
  • Microsoft Visual Studio .NET 2002 Enterprise Architect
  • Microsoft Visual Studio .NET 2002 Enterprise Developer
  • Microsoft Visual Studio .NET 2002 Academic Edition
Keywords: 
kbprb KB319372