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 tags for attributes can incorrectly have namespaces #18

Open jesand opened 9 years ago

jesand commented 9 years ago

When code is generated from a .xsd with namespaces, those namespaces are included in struct field tags for attribute elements. However, encoding/xml does not properly marshal/unmarshal such fields. Deleting the namespace manually from the struct tag corrects the issue.

Here's the command I ran:

$GOPATH/bin/xsd-makepkg -goinst=false -basepath=github.com/jesand/crowds/amt/gen -uri=http://mechanicalturk.amazonaws.com/AWSMechanicalTurkDataSchemas/2005-10-01/QuestionForm.xsd

The resulting code fails to unmarshal MinLength and MaxLength in the following XML:

<QuestionForm xmlns="http://mechanicalturk.amazonaws.com/AWSMechanicalTurkDataSchemas/2005-10-01/QuestionForm.xsd">
          <Question>
            <QuestionIdentifier>nextmove</QuestionIdentifier>
            <DisplayName>The Next Move</DisplayName>
            <IsRequired>true</IsRequired>
            <QuestionContent>
              <Text>
                What are the coordinates of the best move for player "X" in this game?
              </Text>
            </QuestionContent>
            <AnswerSpecification>
              <FreeTextAnswer>
                <Constraints>
                  <Length minLength="2" maxLength="2" />
                </Constraints>
                <DefaultText>C1</DefaultText>
              </FreeTextAnswer>
            </AnswerSpecification>
          </Question>
</QuestionForm>