GitHub - dutchcoders/XMLGen: XMLGen is a tool for generating native Golang types from XML. (original) (raw)

Purpose

XMLGen is a tool for generating native Golang types from XML. This automates what is otherwise a very tedious and error prone task when working with XML.

Build Status GPLv3 License

XMLGen is based on and using code from JSONGen.

Install (using brew)

brew tap dutchcoders/homebrew-xmlgen
brew install xmlgen

Usage

$ xmlgen -h
Usage of xmlgen:
  -dump="NUL": Dump tree structure to file.
  -normalize=true: Squash arrays of struct and determine primitive array type.
  -title=true: Convert identifiers to title case, treating '_' and '-' as word boundaries.

Reading from stdin can be done as follows:

Or a filename can be passed:

Using test.xml as input the example will produce:

➜ xmlgen git:(master) ✗ curl http://www.ibiblio.org/xml/examples/shakespeare/all_well.xml | xmlgen type _ struct { PLAY struct { TITLE string xml:"TITLE" FM struct { P []string xml:"P" } xml:"FM" PERSONAE struct { TITLE string xml:"TITLE" PERSONA []string xml:"PERSONA" PGROUP struct { PERSONA []string xml:"PERSONA" GRPDESCR string xml:"GRPDESCR" } xml:"PGROUP" PERSONA []string xml:"PERSONA" PGROUP struct { PERSONA []string xml:"PERSONA" GRPDESCR string xml:"GRPDESCR" } xml:"PGROUP" PERSONA string xml:"PERSONA" } xml:"PERSONAE" SCNDESCR string xml:"SCNDESCR" PLAYSUBT string xml:"PLAYSUBT" ACT []struct { TITLE string xml:"TITLE" SCENE []struct { TITLE string xml:"TITLE" STAGEDIR string xml:"STAGEDIR" SPEECH []struct { SPEAKER string xml:"SPEAKER" LINE string xml:"LINE" STAGEDIR string xml:"STAGEDIR" } xml:"SPEECH" STAGEDIR string xml:"STAGEDIR" SPEECH []struct { SPEAKER string xml:"SPEAKER" LINE []string xml:"LINE" STAGEDIR string xml:"STAGEDIR" } xml:"SPEECH" STAGEDIR string xml:"STAGEDIR" SPEECH []struct { SPEAKER string xml:"SPEAKER" LINE []string xml:"LINE" STAGEDIR []string xml:"STAGEDIR" LINE []string xml:"LINE" } xml:"SPEECH" STAGEDIR string xml:"STAGEDIR" SPEECH struct { SPEAKER string xml:"SPEAKER" LINE string xml:"LINE" STAGEDIR string xml:"STAGEDIR" } xml:"SPEECH" STAGEDIR string xml:"STAGEDIR" SPEECH []struct { SPEAKER string xml:"SPEAKER" LINE []string xml:"LINE" STAGEDIR string xml:"STAGEDIR" } xml:"SPEECH" STAGEDIR string xml:"STAGEDIR" SPEECH struct { SPEAKER string xml:"SPEAKER" LINE []string xml:"LINE" STAGEDIR string xml:"STAGEDIR" } xml:"SPEECH" STAGEDIR string xml:"STAGEDIR" } xml:"SCENE" EPILOGUE struct { TITLE string xml:"TITLE" SPEECH struct { SPEAKER string xml:"SPEAKER" LINE []string xml:"LINE" } xml:"SPEECH" STAGEDIR string xml:"STAGEDIR" } xml:"EPILOGUE" } xml:"ACT" } xml:"PLAY" }

Parsing

Field Names

Types

Primitive

Object

Lists

Examples of all of the above can be found in test.xml.

Caveats

License

The source of this project is licensed under GNU GPL v3.0, according to http://choosealicense.com/licenses/gpl-3.0/:

Required:

Permitted:

Forbidden:

Feedback

If you find a case that produces incorrect results or you have a feature suggestion, let me know: submit an issue.

Creators

Remco Verhoef

Douglas Hall is the creator of JSONGen. XMLGen is based and using code from JSONGen.