0

When using XSD.exe /c /l:CS /o:temp /order, it doesn't generate the correct order for choices that are in a Items[] array.

XSD:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
    <xsd:group name="Group">
        <xsd:sequence>
            <xsd:element name="BItem2"/>
            <xsd:element name="AItem1"/>
        </xsd:sequence>
    </xsd:group>

    <xsd:element name="MyElement" type="MyClass"/>
    <xsd:complexType name="MyClass">
        <xsd:sequence>
            <xsd:choice>
                <xsd:element name="Whatever"/>
                <xsd:group ref="Group"/>
            </xsd:choice>
        </xsd:sequence>
    </xsd:complexType>
</xsd:schema>

Will output this:

    [System.Xml.Serialization.XmlElementAttribute("AItem1", typeof(object), Order=0)]
    [System.Xml.Serialization.XmlElementAttribute("BItem2", typeof(object), Order=0)]
    [System.Xml.Serialization.XmlElementAttribute("Whatever", typeof(object), Order=0)]
    [System.Xml.Serialization.XmlChoiceIdentifierAttribute("ItemsElementName")]
    public object[] Items {
       // ..
    }

In this case, the XSD generated Order=0 for all XmlElementAttribute and it ordered it alphabetically. BItem2 should be before AItem1.

Is there a way to get this working properly? I can't change the XSD as it comes from a third party.

jsgoupil
  • 3,788
  • 3
  • 38
  • 53
  • May be you can use http://www.xsd2xml.com/ and see – Rao Feb 24 '15 at 20:32
  • @Rao I need to generate Csharp. I am using XmlSchemaImporter+XmlCodeExporter which is the same as XSD.exe – jsgoupil Feb 24 '15 at 20:38
  • Possible duplicate of [XSD Class generators: keeping track of element order](http://stackoverflow.com/questions/18576972/xsd-class-generators-keeping-track-of-element-order) – Paul Sweatte Feb 08 '17 at 17:00

0 Answers0