Creating a Golang Structure from XSD

I want to create a Golang structure from XSD (Structure XSD).

I read a post that generated Go structures from XSD that recommend using go-xsd, but I downloaded go-xsd and installed xsd-makepkg and I cannot generate my structure.

What am I doing?

xsd-makepkg -basepath = "/ Users / XSD_Access /" -goinst = false

-xsd-makepkg: this is the binary file create from apart go-xsd-pkg
-basepath: Contains a route where I have an XSD structure that I want to convert to struct. -goinst: I did not install go-buildrun and I think this is not necessary, for this reason is ser false

What is the result of the team?

A folder ($ GOPATH / usr / Users / XSD_Access /) that contains other folders with all the followers of the XML wrapper

  • docbook.org
  • docs.oasis-open.org
  • kbcafe.com
  • khronos.org
  • schemas.opengis.net
  • thearchitect.co.uk
  • Users
  • www.w3.org

XSD structure

<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> <xs:element name="Request" type="Request"/> <xs:complexType name="Request"> <xs:annotation> <xs:documentation xml:lang="sp"><![CDATA[ Comment xxxxx ]]></xs:documentation> </xs:annotation> <xs:sequence> <xs:element name="idOne" type="xs:string" minOccurs="0" maxOccurs="1"> <xs:annotation> <xs:documentation xml:lang="sp"><![CDATA[Comment xxxxx ]]></xs:documentation> </xs:annotation> </xs:element> <xs:element name="idTwo" type="xs:string" minOccurs="0" maxOccurs="1"> <xs:annotation> <xs:documentation xml:lang="sp"><![CDATA[Comment xxxxxx ]]></xs:documentation> </xs:annotation> </xs:element> </xs:sequence> </xs:complexType> </xs:schema> 

Can someone tell me what I'm doing wrong or what step I skipped that it prevents me from creating a structure from my XSD structure?

Thanks in advance

+8
xml go xsd
source share
2 answers

xsd-makepkg is waiting for xsd files to be downloaded from some network server.

I was also embarrassed by this, since the documentation mentioned creating from local files, but only works if the specified files are already loaded.

-basepath="" determines where these files will be downloaded, and where the generated .go files will be generated.

what you are looking for is the -uri="" argument. -uri="" determines which files should be downloaded and processed. The argument accepts a space-separated uris list, and http:// is optional.

A quick and dirty way to make it work with a local file is to serve the file from a local Apache instance, and then point the program to localhost. This, of course, assumes that you have a web server running.

eg:

 mv *.xsd /var/www/html cd /var/www/html for xsd in *; do xsd-makepkg -uri="127.0.0.1/$xsd"; done 
+5
source share

I found this command line option:

-local = true : Local copy - only download if the file does not exist locally

The statement below worked with mydomain.xsd in the xsd-schema folder.

xsd-makepkg -local = true -uri = "mydomain.xsd" -basepath = "github.com/my_name/xsd-schema"

link: https://github.com/metaleap/go-xsd#command-line-flags-for-go-xsdxsd-makepkg-tool

+2
source share

All Articles