metaleap / go-xsd

[stable since 2013] a lib for loading XML Schema Definition (XSD) files ➜ plus, a tool `makepkg` to code-generate from any *.xsd your Go package with all needed `struct`s to readily `xml.Unmarshal()` documents into, based on the XSD's schema definitions. NOT REALLY MAINTAINED FOR YEARS NOW: try the forks if running into issues.
http://www.reddit.com/r/golang/comments/12g6sl/is_there_a_tool_that_generates_go_source_code_for/
MIT License
217 stars 66 forks source link

Generated structs do not conform to xs:sequence specifications #7

Closed joey-clypd closed 7 years ago

joey-clypd commented 10 years ago

This popped up during testing today. Since xml.Marshal marshals fields in the order they are in the struct, the struct fields need to match the ordering in the schema.

<xs:element name="Top">
    <xs:complexType>
        <xs:sequence>
            <xs:element ref="A" maxOccurs="unbounded"/>
            <xs:element ref="B"/>
            <xs:element ref="C" maxOccurs="unbounded"/>
            <xs:element ref="D"/>
            <xs:element ref="E"/>
            <xs:element ref="F" minOccurs="0"/>
            <xs:element ref="G" maxOccurs="unbounded"/>
            <xs:element ref="H" minOccurs="0" maxOccurs="unbounded"/>
            <xs:element ref="I"/>
            <xs:element ref="J" minOccurs="0" maxOccurs="unbounded"/>
            <xs:element ref="K" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>

Actual Output:

type TxsdTop struct {
    XsdGoPkgHasElem_B
    XsdGoPkgHasElems_C
    XsdGoPkgHasElem_F
    XsdGoPkgHasElems_H
    XsdGoPkgHasElems_J
    XsdGoPkgHasElems_K
    XsdGoPkgHasElems_A
    XsdGoPkgHasElem_D
    XsdGoPkgHasElem_E
    XsdGoPkgHasElems_G
    XsdGoPkgHasElem_I
}

Expected Output:

type TxsdTop struct {
    XsdGoPkgHasElems_A
    XsdGoPkgHasElem_B
    XsdGoPkgHasElems_C
    XsdGoPkgHasElem_D
    XsdGoPkgHasElem_E
    XsdGoPkgHasElem_F
    XsdGoPkgHasElems_G
    XsdGoPkgHasElems_H
    XsdGoPkgHasElem_I
    XsdGoPkgHasElems_J
    XsdGoPkgHasElems_K
}