PRB: MSXML 4.0: Error Message When You Load an XSD Schema in an XMLSchemaCache Object (316635)



The information in this article applies to:

  • Microsoft XML 4.0

This article was previously published under Q316635

SYMPTOMS

When you load an XML Schema definition language (XSD) schema into an MSXML 4.0 XMLSchemaCache object, you may receive the following error message:
<all> is not the only particle in a <group> or is being used as an extension.

CAUSE

This may occur if the schema contains a complex type that derives from another complex type whose content model is defined by using an <xsd:all> grouping particle, as follows:
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 <xsd:complexType name="address">
  <xsd:all>
   <xsd:element name="name"   type="xsd:string"/>
   <xsd:element name="street" type="xsd:string"/>
   <xsd:element name="city"   type="xsd:string"/>
  </xsd:all>
 </xsd:complexType>

 <xsd:complexType name="USAddress">
  <xsd:complexContent>
   <xsd:extension base="address">
    <xsd:all>
     <xsd:element name="state" type="USState"/>
     <xsd:element name="zipcode" type="xsd:positiveInteger"/>
    </xsd:all>
   </xsd:extension>
  </xsd:complexContent>
 </xsd:complexType>
</xsd:schema>
				

RESOLUTION

To work around this problem, use either of the following methods:
  • Use the <sequence> element rather than the <all> element to define the content model of the parent type.
  • Use the <sequence> element to define a new complex type instead of extending a type that uses the <all> element.
For example, you can use the following schema:
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 <xsd:complexType name="address">
  <xsd:all>
   <xsd:element name="name"   type="xsd:string"/>
   <xsd:element name="street" type="xsd:string"/>
   <xsd:element name="city"   type="xsd:string"/>
  </xsd:all>
 </xsd:complexType>

 <xsd:complexType name="USAddress">
  <xsd:all>
   <xsd:element name="name"   type="xsd:string"/>
   <xsd:element name="street" type="xsd:string"/>
   <xsd:element name="city"   type="xsd:string"/>
   <xsd:element name="state" type="xsd:string"/>
   <xsd:element name="zipcode" type="xsd:positiveInteger"/>
  </xsd:all>
 </xsd:complexType>
</xsd:schema>
				

STATUS

This behavior is by design.

MORE INFORMATION

According to the World Wide Web Consortium (W3C) specifications, <all> model groups may appear only at the top level of a complexType or group element, and must be the only particle in the group.

When an extension type is built in XSD, it is regarded as a sequence that contains the base type and the extension. For example, the derived USAddress complexType element from the schema that is described in the "Cause" section resembles the following:
<xsd:complexType name="USAddress">
 <xsd:sequence>
  <xsd:all>
   <xsd:element name="name" type="xsd:string"/>
   <xsd:element name="street" type="xsd:string"/>
   <xsd:element name="city" type="xsd:string"/>
  </xsd:all>
  <xsd:all>
   <xsd:element name="state" type="USState"/>
   <xsd:element name="zipcode" type="xsd:positiveInteger"/>
  </xsd:all>  
 </xsd:sequence>
</xsd:complexType>
				
This violates the rule that <all> model groups must appear at the top level of a complexType or group element, and must be the only particle in the group.

Steps to Reproduce Behavior

Save the sample schema that is described in the "Cause" section in a file named Address-schema.xsd, and then add the schema to an MSXML 4.0 XMLSchemaCache object, as in the following Microsoft Visual Basic sample:
  Dim xmlschema As MSXML2.XMLSchemaCache40
  Set xmlschema = New MSXML2.XMLSchemaCache40
  xmlschema.Add "", app.path & "\address-schema.xsd"
				
When the Add method is called, the XSD is checked to ensure that it conforms to the W3C XSD specifications. Because this schema does not conform to the specifications, you receive an error message.

REFERENCES

For more information on W3C specifications, see the following Web sites:

XML Representation of Model Group Schema Components
http://www.w3.org/TR/xmlschema-1/#declare-contentModel

Constraints on Particle Schema Components (including extensions):
http://www.w3.org/TR/xmlschema-1/#coss-particle


Modification Type:MajorLast Reviewed:3/18/2002
Keywords:kbDSupport kbprb KB316635