Microsoft KB Archive/316297

= PRB: &quot;Schema Is Non-Deterministic&quot; Error Message When You Add XSD to XMLSchemaCache Object =

Article ID: 316297

Article Last Modified on 3/1/2002

-

APPLIES TO


 * Microsoft XML Core Services 4.0

-



This article was previously published under Q316297



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



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



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



STATUS
This behavior is by design.



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

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:

&quot;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.&quot;

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

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:choice>  <xs:element name=&quot;first_name&quot; type=&quot;xs:string&quot;/> <xs:element name=&quot;last_name&quot; type=&quot;xs:string&quot;/> </xs:sequence>  <xs:element name=&quot;first_name&quot; type=&quot;xs:string&quot;/> <xs:element name=&quot;middle_name&quot; type=&quot;xs:string&quot;/> <xs:element name=&quot;lastname_name&quot; type=&quot;xs:string&quot;/> </xs:sequence> </xs:choice> </xs:complexType>

</xs:schema> </li> <li> Sample 2: Catalog.xsd <xs:schema xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot; targetNamespace=&quot;urn:Catalog&quot; xmlns=&quot;urn:Catalog&quot; elementFormDefault=&quot;qualified&quot;>

<xs:element name=&quot;catalog&quot; type=&quot;CatalogData&quot;/>

  <xs:element name=&quot;book&quot; type=&quot;bookdata&quot; minOccurs=&quot;0&quot; maxOccurs=&quot;unbounded&quot;/> </xs:sequence> </xs:complexType>



<xs:choice>  <xs:element name=&quot;author&quot; type=&quot;xs:string&quot;/> <xs:element name=&quot;title&quot; type=&quot;xs:string&quot; minOccurs=&quot;0&quot;/> </xs:sequence>  <xs:element name=&quot;title&quot; type=&quot;xs:string&quot; minOccurs=&quot;0&quot;/> <xs:element name=&quot;author&quot; type=&quot;xs:string&quot;/> </xs:sequence> </xs:choice> </xs:complexType>

</xs:schema> </li></ul>

Steps to Reproduce Behavior
<ol> <li>Use Notepad to create and save the People.xsd sample schema document in the root folder of your hard disk.</li> <li>Open a new Standard EXE project in Visual Basic 6.0.</li> <li>Add a project reference to Microsoft XML, v4.0.</li> <li>Drag a command button to Form1.</li> <li> 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 &quot;urn:People&quot;, &quot;c:\people.xsd&quot; </li> <li>Save and then run the project. Click the command button when the form is displayed.</li> <li> Use the following definition for the personData complexType in the commented Solution section of sample 1 to replace the active definition:   <xs:element name=&quot;first_name&quot; type=&quot;xs:string&quot;/> <xs:choice> <xs:element name=&quot;last_name&quot; type=&quot;xs:string&quot;/>  <xs:element name=&quot;middle_name&quot; type=&quot;xs:string&quot;/> <xs:element name=&quot;lastname_name&quot; type=&quot;xs:string&quot;/> </xs:sequence> </xs:choice> </xs:sequence> </xs:complexType> </li> <li>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.</li></ol>

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

<pre class="fixed_text">#import <msxml4.dll>

Keywords: kbprb KB316297

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.