0
在XSD中,我有一個從基類SaleType擴展的ReturnType。我不關心元素在xml中出現的順序。忽略從基類型擴展的元素外觀順序
我可以更改XSD,但我無法更改xml的寫入方式。出於某種原因,寫入xml的方式不是按照XSD中定義的順序排列。我可以使訂單在基本類型中不起作用,但在擴展中。我該如何解決?
<xs:complexType name="SaleType">
<xs:sequence>
<xs:choice minOccurs="0" maxOccurs="unbounded"> <!--adding this ignores the order for Sale but does not enforce it to the extensions-->
<xs:element name="ItemID" type="xs:string" />
xs:element name="Description" type="xs:string" minOccurs="0"/>
</xs:choice>
</xs:sequence>
</xs:complexType>
<xs:complexType name="ReturnType">
<xs:complexContent>
<xs:extension base="SaleType">
<xs:sequence>
<xs:element name="Reason" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<!--Even though Description appears before ItemID, this xml validates since Reason is at the end-->
<Return>
<Description>Item 123</Description>
<ItemID>123</ItemID>
<Reason>R1</Reason>
</Return>
<!--This xml does not validate since Reason is at the beginning-->
<Return>
<Reason></Reason>
<Description>Item 123</Description>
<ItemID>123</ItemID>
</Return>