开发者

xsd.exe creating invalid constraints in dataset from xsd file

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 indica开发者_StackOverflow社区ting 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>


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜