Generate Go Structures from XSD

Recently, I plan to make a project using Go. My problem: given the XSD file, how to automatically generate structures in Go to represent XML elements. This is similar to using 'xjc' to generate java classes from XSD. So, are there any tools or packages for this in Go?

Thanks in advance.

+8
xml go xsd jaxb xjc
source share
2 answers

It looks like you might need TLC support for 1.2, but there is: https://github.com/metaleap/go-xsd

Who has a set of sample packages that were generated for different common XML formats: https://github.com/metaleap/go-xsd-pkg

+6
source share

I started writing github.com/ivarg/goxsd to create XML structures from the XSD specification. Although it is still incomplete with respect to the XSD schema scheme , it covers some of the most common use cases. Perhaps this may be helpful to others.

It is currently written to run from the command line or as a go generate statement in the source file. It creates formatted code and provides the following options:

  • generate exported or unfulfilled XML structures
  • specify the output file (default is standard output)
  • specify package name

Currently, it only processes shema XSD files on the local file system and does not process namespaces (they are ignored) or generate verification code.

+2
source share

All Articles