Microsoft KB Archive/815107

= PRB: When You Generate Managed Classes, the mixed Attribute Is Ignored When the Element Contains the anyAttribute Property =

Article ID: 815107

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
You can generate managed classes for XML Schemas by using the XML Schema Definition Tool (Xsd.exe). However, when you generate managed classes for an XML Schema that contains the anyAttribute element under the mixed attribute, you may not find the XmlTextAttribute class as a public member for the generated class.



CAUSE
The mixed attribute indicates whether character data is permitted to appear between the child elements of the complexType element. The default value of mixed is false. However, when you add anyAttribute to a complex type element that has mixed set to true, the mixed attribute is ignored.



WORKAROUND
To work around this problem, do not use anyAttribute inside mixed attributes when you want to enter character data between child elements.

For more information about XML Schema design patterns, visit the following Microsoft Developer Network (MSDN) Web site:

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



STATUS
This behavior is by design.



Steps to Reproduce the Behavior
 Open a text editor such as Notepad.  Paste the following schema in the text editor:       <xsd:anyAttribute /> </xsd:extension> </xsd:simpleContent> </xsd:complexType> </xsd:element> </xsd:schema> </li> Save the file as C:\MyXmlSchema.xsd.</li> Start Microsoft Visual Studio .NET Command Prompt.</li>  To generate the classes, type the following command at the command prompt, and then press ENTER:

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>  The generated class looks similar to the following:

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://www.w3.org/2000/09/xmldsig#&quot;), _ System.Xml.Serialization.XmlRootAttribute([Namespace]:=&quot;http://www.w3.org/2000/09/xmldsig#&quot;, IsNullable:=false)> _ Public Class CurrencyMainElement '    <System.Xml.Serialization.XmlAttributeAttribute>  _ Public CurrencyAttribute 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://www.w3.org/2000/09/xmldsig#&quot;)] [System.Xml.Serialization.XmlRootAttribute(Namespace=&quot;http://www.w3.org/2000/09/xmldsig#&quot;, IsNullable=false)] public class CurrencyMainElement { ///    [System.Xml.Serialization.XmlAttributeAttribute] public string CurrencyAttribute; ///    [System.Xml.Serialization.XmlAnyAttributeAttribute] public System.Xml.XmlAttribute[] AnyAttr; } </li> You may notice the behavior that is described in the &quot;Symptoms&quot; section of this article.</li></ol>

<div class="references_section">