PRB: XmlElementAttribute Is Missing for the Generated Class Members While Using Xsd.exe (816222)
The information in this article applies to:
- Microsoft .NET Framework 1.0
- Microsoft .NET Framework 1.1
- Microsoft Visual C# .NET (2002)
- Microsoft Visual C# .NET (2003)
- Microsoft Visual Basic .NET (2002)
- Microsoft Visual Basic .NET (2003)
SYMPTOMSWhen you use the XML Schema Definition Tool (Xsd.exe) to
generate managed classes from an XML schema, the XmlElementAttribute class is not generated for complex type member elements of the
top-level elements of an included schema. You see this behavior when the value
of the elementFormDefault attribute of the <xs:schema> element in the including
schema is set to qualified, even though the included schema sets the elementFormDefault attribute to unqualified.CAUSEThis behavior occurs when the elementFormDefault attribute of the element of the including schema
<xs:schema> is set to qualified. While processing the XML schema includes, the schema compiler
combines the schemas in the include hierarchy to generate a Single Compiled
Schema (SOM). The elementFormDefault and attributeFormDefault schema settings for compiled schema reflect the settings that are
specified for the top-most schema in the include hierarchy. Therefore, when the
elementFormDefault attribute of the top-most <xs:schema> element of the schema is
set to qualified, XmlElementAttribute is not generated for the complex type member
elements of the included schema.WORKAROUNDTo work around this problem, manually add the XmlElementAttribute class to the complex type element members of base schema. Add XmlElementAttribute only when you must serialize the members as unqualified elements when an instance of the type is serialized using the XmlSerializer. To do so, add the following statement before each member of the
generated class: Visual Basic .NET Code<System.Xml.Serialization.XmlElementAttribute(Form:=System.Xml.Schema.XmlSchemaForm.Unqualified)> _ Visual C# .NET Code[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] Note No changes are required in the generated class when you are not
concerned about the serialization of the members as qualified elements.
STATUS This
behavior is by design.REFERENCES For additional
information about XML Schema, click the following article number to view the
article in the Microsoft Knowledge Base: 313826
INFO: Roadmap for XML Schemas in the .NET
Modification Type: | Major | Last Reviewed: | 5/14/2003 |
---|
Keywords: | kbCodeGen kbXML kbSchema kbprb KB816222 kbAudDeveloper |
---|
|