Information
Article ID13
Created On6/5/2008
Modified6/5/2008
Share With Others

Non-Deterministic Schemas

This article describes approaches for dealing with the error "Schemas Run-time error '-2147467259(80004005)': Schema is non-deterministic" when generating clode using Liquid XML Data Binding.

The error your seeing is coming from MSXML. Basically it says your schema does not comply with the W3C XSD standard. We have found, because of the complex nature of the XSD standard that there are a lot of tools out there that create invalid documents, so these errors are not un-common.

Microsoft's implementation seems to be the one that best reflects the standard, and so we use it internally within the generator.

The attached article describes why the Non-Deterministic error occurs.

PRB: "Schema Is Non-Deterministic" Error Message When You Add XSD to XMLSchemaCache Object

View products that this article applies to.

Article ID

:

316297

Last Review

:

March 1, 2002

Revision

:

1.0

This article was previously published under Q316297

On This Page

SYMPTOMS

SYMPTOMS

CAUSE

CAUSE

RESOLUTION

RESOLUTION

STATUS

STATUS

MORE INFORMATION

MORE INFORMATION

 

Sample Nondeterministic XSDs

Sample Nondeterministic XSDs

 

Steps to Reproduce Behavior

Steps to Reproduce Behavior

APPLIES TO

APPLIES TO

SYMPTOMS

When you add an XML Schema Definition (XSD) to the Microsoft XML 4.0 XMLSchemaCache object, you may receive the following error message:

Run-time error '-2147467259(80004005)': Schema is non-deterministic

Back to the top

Back to the top

CAUSE

The content model of a type definition in the XSD is non-deterministic (ambiguous). For additional information about deterministic content models, see the "More Information" section of this article.

Back to the top

Back to the top

RESOLUTION

Identify the type definition that contains the non-deterministic content model and make the changes required to make the content model deterministic (unambiguous).

Back to the top

Back to the top

STATUS

This behavior is by design.

Back to the top

Back to the top

MORE INFORMATION

Appendix E of the World Wide Web Consortium (W3C) Extensible Markup Language (XML) specifications states that XML processors are permitted to flag non-deterministic content models as errors; for more information, see the following Web site:

http://www.w3.org/TR/2000/REC-xml-20001006#determinism (http://www.w3.org/TR/2000/REC-xml-20001006#determinism)

The following extract from the cited appendix provides an example of a non-deterministic content model. The extract explains the change that is necessary to make the content model deterministic:

"The content model ((b, c) | (b, d)) is non-deterministic, because given an initial b the XML processor cannot know which b in the model is being matched without looking ahead to see which element follows the b. In this case, the two references to b can be collapsed into a single reference, making the model read (b, (c | d)). An initial b now clearly matches only a single name in the content model. The processor doesn't need to look ahead to see what follows; either c or d would be accepted."

Other content models also can be non-deterministic. The following sample schema documents include non-deterministic content models.

Back to the top

Back to the top

Sample Nondeterministic XSDs

Each sample includes an Explanation section to clarify what makes the XSDs non-deterministic. Each sample also includes a Solution section that describes the change required to make the content model deterministic.

Sample 1: People.xsd

<xs:schema xmlns:xs=http://www.w3.org/2001/XMLSchema
           targetNamespace="urn:People" xmlns="urn:People" elementFormDefault="qualified">
  <xs:element name="people" type="PeopleData"/>
  <xs:complexType name="PeopleData">
    <xs:sequence>
      <xs:element name="person" type="persondata" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType> 

  <!--
Explanation: The content model of the personData complexType is non-deterministic.
This is an example of the ((b, c) | (b, d)) non-deterministic content model with a small difference.
In this sample, the second sequence lists three elements and is of the form ((b,c) | (b,d,c)).
The XML processor must look ahead to determine the matching sequence when it encounters b.
This requirement to look ahead makes the content model non-deterministic.
  -->
  <xs:complexType name="persondata">
   <xs:choice>
    <xs:sequence>
      <xs:element name="first_name" type="xs:string"/>
      <xs:element name="last_name" type="xs:string"/>
    </xs:sequence>
    <xs:sequence>
      <xs:element name="first_name" type="xs:string"/>
      <xs:element name="middle_name" type="xs:string"/>
      <xs:element name="lastname_name" type="xs:string"/>
    </xs:sequence>
   </xs:choice>
  </xs:complexType> 

  <!--
Solution: Use a (b,(c | (d,c))) content model.

 <xs:complexType name="persondata">
   <xs:sequence>
    <xs:element name="first_name" type="xs:string"/>
    <xs:choice>
      <xs:element name="last_name" type="xs:string"/>
      <xs:sequence>
        <xs:element name="middle_name" type="xs:string"/>
        <xs:element name="lastname_name" type="xs:string"/>
      </xs:sequence>
    </xs:choice>
   </xs:sequence>
 </xs:complexType>
  -->

</xs:schema>

 

Sample 2: Catalog.xsd

 

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"

           targetNamespace="urn:Catalog" xmlns="urn:Catalog" elementFormDefault="qualified">

 

  <xs:element name="catalog" type="CatalogData"/>

 

  <xs:complexType name="CatalogData">

    <xs:sequence>

      <xs:element name="book" type="bookdata" minOccurs="0"

      maxOccurs="unbounded"/>

      </xs:sequence>

  </xs:complexType>

 

 

  <!--

Explanation: The content model of the bookdata complexType is non-deterministic.

The title elements in both of the sequences that are defined for the choice element have a minOccurs property setting of 0.

The processor cannot determine the matching sequence when a title element is not present in the XML instance document

(possibly because the minOccurs property of the element is set to 0).

  -->

 

 

  <xs:complexType name="bookdata">

 

   <xs:choice>

    <xs:sequence>

      <xs:element name="author" type="xs:string"/>

      <xs:element name="title" type="xs:string" minOccurs="0"/>

    </xs:sequence>

    <xs:sequence>

      <xs:element name="title" type="xs:string" minOccurs="0"/>

      <xs:element name="author" type="xs:string"/>

    </xs:sequence>

    </xs:choice>

 

  </xs:complexType>

 

 

  <!--

Solution: This content model definition for the bookdata complexType specifies

that the author element and the title element can occur in any order in the XML instance document,

and that the presence of the title element is optional.

 

The same requirement can be specified using an all element as shown in the following definition.

 

  <xs:complexType name="bookdata">

    <xs:all>

       <xs:element name="author" type="xs:string"/>

       <xs:element name="title" type="xs:string" minOccurs="0"/>

    </xs:all>

  </xs:complexType name="bookdata">

  -->

 

 

</xs:schema>

 

 

Back to the top

Back to the top

Steps to Reproduce Behavior

1.

Use Notepad to create and save the People.xsd sample schema document in the root folder of your hard disk.

2.

Open a new Standard EXE project in Visual Basic 6.0.

3.

Add a project reference to Microsoft XML, v4.0.

4.

Drag a command button to Form1.

5.

Paste the following code in the Click event procedure of the command button:

Dim sc As MSXML2.XMLSchemaCache40
Set sc = New MSXML2.XMLSchemaCache40
sc.Add "urn:People", "c:\people.xsd"

6.

Save and then run the project. Click the command button when the form is displayed.

7.

Use the following definition for the personData complexType in the commented Solution section of sample 1 to replace the active definition:

<xs:complexType name="persondata">

   <xs:sequence>

    <xs:element name="first_name" type="xs:string"/>

    <xs:choice>

      <xs:element name="last_name" type="xs:string"/>

      <xs:sequence>

        <xs:element name="middle_name" type="xs:string"/>

        <xs:element name="lastname_name" type="xs:string"/>

      </xs:sequence>

    </xs:choice>

   </xs:sequence>

 </xs:complexType>

 

8.

Save the changes to the schema document and try to add the XSD to the MSXML 4.0 XMLSchemaCache object by re-executing the Visual Basic code. Note that the schema is added successfully and that no errors messages are displayed.

Note: The schema compilation error is returned as _com_error if you are programming in Visual C++ with the following:

#import <msxml4.dll>