views:

147

answers:

1

I have a sequence with an allowed minimum length of zero in my xsd. When I try and load an xml file which doesn't have any elements of the sequence into the DataSet that xsd.exe created I get an exception indicating that my file violated one of the DataSet's constraints. The xml file validates against the schema so I know it's valid. Is there anything I can do to make the tool generate a valid dataset?

<xs:sequence minOccurs="0" maxOccurs="unbounded">
 <xs:element name="Numbers" type="xs:double"/>
</xs:sequence>

Edit: if I change my schema to this the generated code works properly. It looks wrong to me though since it appears to be implying that I could have sequence items with nothing in them, which doesn't make any sense.

<xs:sequence minOccurs="0" maxOccurs="unbounded">
 <xs:element name="Numbers" type="xs:double" minOccurs="0"/>
</xs:sequence>
+1  A: 

This sounds like it is because of the way that xsd.exe handles minOccurs and maxOccurs. This MSDN article describes the way that xsd.exe handles minOccurs / maxOccurs. This section of that article seems to tally with your initial problem:

A loss of definition precision occurs when Xsd.exe ignores the minOccurs attribute in the case when the maxOccurs attribute value dictates an array binding. A reverse translation from the generated array to a new declaration produces not the original minOccurs value but a value of 0, plus a maxOccurs value of unbounded.

amelvin
Thank you. That does appear to describe my problem.
Dan Neely