BUG: XSD.exe generates cases that allow for multiple entries for all members of choice even though only one member is unbounded (816226)
The information in this article applies to:
- Microsoft .NET Framework 1.1
- Microsoft .NET Framework 1.0
- Microsoft Visual Basic .NET (2003)
- Microsoft Visual Basic .NET (2002)
- Microsoft Visual C# .NET (2003)
- Microsoft Visual C# .NET (2002)
SYMPTOMSIn an XML Schema project, the XSD tool incorrectly
interprets the maxOccurs attribute for all members of the choice element as unbounded if
one of the following criteria is true:
- If the maxOccurs attribute is set to a value that is greater than 1.
- If the maxOccurs attribute is unbounded for at least one member of the choice
element.
With the managed class that is generated by the XSD tool,
multiple unbounded entries can be added for all the members of the choice
element in the XML document. WORKAROUNDThere is no direct workaround for this problem. However, in
some cases you can work around this problem by using two choice elements. The
first choice element has members with the maxOccur attribute set to one, and the second choice element has members
with a maxOccur attribute that is set to greater than one. The following schema
code describes the changes that are required in choice elements of the schema
that are used in the "More Information" section of this article: <?xml version="1.0" ?>
<xs:schema id="Root" targetNamespace="http://tempuri.org/customer.xsd" xmlns:mstns="http://tempuri.org/customer.xsd" xmlns="http://tempuri.org/customer.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" attributeFormDefault="qualified" elementFormDefault="qualified">
<xs:element name="Root" msdata:IsDataSet="true" msdata:EnforceConstraints="False">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="Customers" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:choice minOccurs="0">
<xs:element name="workphone" type="xs:string" minOccurs="0" maxOccurs="unbounded" />
</xs:choice>
<xs:choice minOccurs="0">
<xs:element name="homephone" type="xs:string" minOccurs="0" />
<xs:element name="cellphone" type="xs:string" minOccurs="0" />
</xs:choice>
<xs:element name="CustName" type="xs:string" minOccurs="0" />
<xs:element name="CustID" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
<xs:key name="RootKey1">
<xs:selector xpath=".//mstns:Customers" />
<xs:field xpath="mstns:CustID" />
</xs:key>
</xs:element>
</xs:schema>
STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are
listed at the beginning of this article.
REFERENCES For additional information about XML Schema in
the .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
Modification Type: | Minor | Last Reviewed: | 9/15/2005 |
---|
Keywords: | kbvs2002sp1sweep kbCodeGen kbXML kbSerial kbSchema kbbug KB816226 kbAudDeveloper |
---|
|