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
216 stars 66 forks source link

How to use this tool to generate go structs from xsd files #29

Open RahulMetangale opened 7 years ago

RahulMetangale commented 7 years ago

Hello,

I am new to golang and i am not clear on how to setup this command line tool. Can you point me in right direction, i am using windows OS. I need help with following:

  1. Setup this project
  2. Use this to convert xsd files to go classes

Thanks, Rahul

emicklei commented 7 years ago

i decided not to use the tool but the package directly

package main

import (
    "log"

    xsd "github.com/metaleap/go-xsd"
)

func main() {
    var (
        sd  *xsd.Schema
        err error
    )
    xsd.PkgGen.BaseCodePath = "/Users/myuser/go/src/myorganisation.com/myprogram"
    if sd, err = xsd.LoadSchema("my.xsd", true); err != nil {
        log.Fatal(err)
    }
    sd.MakeGoPkgSrcFile()
}