考虑以下简单模式:
<xs:schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="MyRoot">
<xs:complexType>
<xs:sequence>
<xs:group ref="MyChoice" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:group name="MyChoice">
<xs:choice>
<xs:element name="a" type="xs:string"/>
<xs:element name="b" type="xs:string"/>
<xs:element name="c" type="xs:string"/>
</xs:choice>
</xs:group>
</xs:schema>
当使用xsd.exe(VS2017)将其转换为C#代码时,我得到以下输出:
public partial class MyRoot {
private string[] aField;
private string[] bField;
private string[] cField;
// ... omitted for brevity ...
}
此代码有一个主要问题:在XSD / XML中,所有子元素(a,b和c)都被排序。 现在,由于C#类中的每个子元素都有三个不同的数组,因此该顺序已丢失。
xsd.exe做错了吗?还是我使用错了?还是.xsd文件有缺陷?