Microsoft KB Archive/815107

From BetaArchive Wiki

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:

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Open a text editor such as Notepad.
  2. Paste the following schema in the text editor:

    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    xmlns:ds="http://www.w3.org/2000/09/xmldsig#" 
    targetNamespace="http://www.w3.org/2000/09/xmldsig#" version="0.1" 
    elementFormDefault="qualified">
       <xsd:element name="CurrencyMainElement">
          <xsd:complexType mixed="true">
             <xsd:simpleContent>
                <xsd:extension base="xsd:decimal">
                   <xsd:attribute name="CurrencyAttribute" type="xsd:string" />
                   <xsd:anyAttribute />
                </xsd:extension>
             </xsd:simpleContent>
          </xsd:complexType>
       </xsd:element>
    </xsd:schema>
  3. Save the file as C:\MyXmlSchema.xsd.
  4. Start Microsoft Visual Studio .NET Command Prompt.
  5. 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
  6. The generated class looks similar to the following:

    Visual Basic .NET

    '------------------------------------------------------------------------------
    ' <autogenerated>
    '     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.
    ' </autogenerated>
    '------------------------------------------------------------------------------
    
    Option Strict Off
    Option Explicit On
    
    Imports System.Xml.Serialization
    
    '
    'This source code was auto-generated by xsd, Version=1.0.3705.0.
    '
    
    '<remarks/>
    <System.Xml.Serialization.XmlTypeAttribute([Namespace]:="http://www.w3.org/2000/09/xmldsig#"),  _
     System.Xml.Serialization.XmlRootAttribute([Namespace]:="http://www.w3.org/2000/09/xmldsig#", IsNullable:=false)>  _
    Public Class CurrencyMainElement
        
        '<remarks/>
        <System.Xml.Serialization.XmlAttributeAttribute()>  _
        Public CurrencyAttribute As String
        
        '<remarks/>
        <System.Xml.Serialization.XmlAnyAttributeAttribute()>  _
        Public AnyAttr() As System.Xml.XmlAttribute
    End Class

    Visual C# .NET

    //------------------------------------------------------------------------------
    // <autogenerated>
    //     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.
    // </autogenerated>
    //------------------------------------------------------------------------------
    
    // 
    // This source code was auto-generated by xsd, Version=1.0.3705.0.
    // 
    using System.Xml.Serialization;
    
    
    /// <remarks/>
    [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://www.w3.org/2000/09/xmldsig#")]
    [System.Xml.Serialization.XmlRootAttribute(Namespace="http://www.w3.org/2000/09/xmldsig#", IsNullable=false)]
    public class CurrencyMainElement {
        
        /// <remarks/>
        [System.Xml.Serialization.XmlAttributeAttribute()]
        public string CurrencyAttribute;
        
        /// <remarks/>
        [System.Xml.Serialization.XmlAnyAttributeAttribute()]
        public System.Xml.XmlAttribute[] AnyAttr;
    }
  7. You may notice the behavior that is described in the "Symptoms" section of this article.


REFERENCES

For additional information about XML Schemas in the Microsoft .NET Framework, click the following article number to view the article in the Microsoft Knowledge Base:

313826 INFO: Roadmap for XML Schemas in the .NET Framework


Keywords: kbschema kbcodegen kbxml kbprb KB815107