Microsoft KB Archive/815108

= PRB: &quot;Schema Validation Warning&quot; When You Generate a Managed Class for XML Schema with an any Element Declaration and a Local Element Declaration =

Article ID: 815108

Article Last Modified on 1/11/2007

-

APPLIES TO


 * Microsoft .NET Framework 1.1
 * Microsoft .NET Framework 1.0
 * Microsoft Visual Basic .NET 2003 Standard Edition
 * Microsoft Visual Basic .NET 2002 Standard Edition
 * Microsoft Visual C# .NET 2003 Standard Edition
 * Microsoft Visual C# .NET 2002 Standard Edition

-



SYMPTOMS
When you create an XML Schema that contains an any element without a namespace declaration, or if the value for the namespace is set to any value other than ##other and ##local along with a local element declaration, you may receive the following warnings when you generate managed classes for the schema by using the XML Schema Definition Tool (Xsd.exe):

Schema validation warning: The content model must be deterministic. Wildcard dec laration along with a local element declaration causes content model to become a mbiguous. An error occurred at file:Filename.xsd(Line, Column).

Warning: Schema could not be validated. Class generation may fail or may produce incorrect results.



CAUSE
The any element permits any element from the specified namespace to appear in the containing sequence or the choice element. Xsd.exe does not support the namespace for the any element and the warning messages display when you generate managed classes.



WORKAROUND
To work around this problem, do not declare local elements when you declare an any element. When you set the value for the namespace for the any element as &quot;##other&quot; or &quot;##local&quot;, you may not get warnings when you generate managed classes. However, when you build a library for the generated managed class and then generate schema from the library by using XSD.exe, you may not get the namespace declaration in the generated schema.

For more information about XML Schema design patterns, visit the following MSDN Web site:

http://msdn.microsoft.com/xml/



STATUS
This behavior is by design.



Steps to Reproduce the Behavior
 Start Microsoft Visual Studio .NET. On the File menu, point to New, and then click File. Select General under Categories, select XML Schema under Templates, and then click Open. By default, XMLSchema1 is created.  On the XML tab, replace the existing code with the following code:    <xs:complexType mixed=&quot;true&quot;> <xs:sequence> <xs:any minOccurs=&quot;0&quot; /> <xs:element name=&quot;MyElement&quot; type=&quot;xs:string&quot; /> </xs:sequence> <xs:anyAttribute /> </xs:complexType> </xs:element> </xs:schema> </li> On the File menu, click Save FileName As.</li> Type C:\MyXmlSchema.xsd as the File name, and then click Save.</li> Start Visual Studio .NET Command Prompt.</li>  To generate the classes, type the following command at the command prompt and then press ENTER key:

In Microsoft Visual Basic .NET xsd /c /l:vb /o:C:\ C:\MyXmlSchema.xsd In Microsoft Visual C# .NET xsd /c /l:cs /o:C:\ C:\MyXmlSchema.xsd </li>  You may notice the warnings that are described in the &quot;Symptoms&quot; section of this article.

The following managed class is generated:

Visual Basic .NET '-- ' '    This code was generated by a tool. '    Runtime Version: 1.0.3705.0 ' '    Changes to this file may cause incorrect behavior and will be lost if '     the code is regenerated. ' '--

Option Strict Off Option Explicit On

Imports System.Xml.Serialization

' 'This source code was auto-generated by xsd, Version=1.0.3705.0. '

' <System.Xml.Serialization.XmlTypeAttribute([Namespace]:=&quot;http://tempuri.org/XMLSchema.xsd&quot;), _ System.Xml.Serialization.XmlRootAttribute([Namespace]:=&quot;http://tempuri.org/XMLSchema.xsd&quot;, IsNullable:=false)> _ Public Class Root '    <System.Xml.Serialization.XmlTextAttribute,  _ System.Xml.Serialization.XmlAnyElementAttribute> _ Public Any As System.Xml.XmlNode '    Public MyElement As String '    <System.Xml.Serialization.XmlAnyAttributeAttribute>  _ Public AnyAttr As System.Xml.XmlAttribute End Class Visual C# .NET //-- // //    This code was generated by a tool. //    Runtime Version: 1.0.3705.0 // //    Changes to this file may cause incorrect behavior and will be lost if //     the code is regenerated. // //--

// // This source code was auto-generated by xsd, Version=1.0.3705.0. // using System.Xml.Serialization;

/// [System.Xml.Serialization.XmlTypeAttribute(Namespace=&quot;http://tempuri.org/XMLSchema.xsd&quot;)] [System.Xml.Serialization.XmlRootAttribute(Namespace=&quot;http://tempuri.org/XMLSchema.xsd&quot;, IsNullable=false)] public class Root { ///    [System.Xml.Serialization.XmlTextAttribute] [System.Xml.Serialization.XmlAnyElementAttribute] public System.Xml.XmlNode[] Any; ///    public string MyElement; ///    [System.Xml.Serialization.XmlAnyAttributeAttribute] public System.Xml.XmlAttribute[] AnyAttr; } </li></ol>

<div class="references_section">