{"id":13563489,"url":"https://github.com/twpayne/go-xmlstruct","last_synced_at":"2025-04-07T09:19:37.025Z","repository":{"id":63324680,"uuid":"566888510","full_name":"twpayne/go-xmlstruct","owner":"twpayne","description":"Generate Go structs from multiple XML documents.","archived":false,"fork":false,"pushed_at":"2025-02-17T20:20:32.000Z","size":28531,"stargazers_count":83,"open_issues_count":1,"forks_count":10,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-02T00:34:49.392Z","etag":null,"topics":["generator","go","golang","schema","struct","xml","xsd"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/twpayne.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-11-16T16:18:55.000Z","updated_at":"2025-03-17T22:24:59.000Z","dependencies_parsed_at":"2024-06-20T08:24:53.363Z","dependency_job_id":"4468598d-dc99-48eb-b426-666761d83f5d","html_url":"https://github.com/twpayne/go-xmlstruct","commit_stats":{"total_commits":116,"total_committers":3,"mean_commits":"38.666666666666664","dds":0.08620689655172409,"last_synced_commit":"58a20663146331a8c87e4231851e90d061fc9daa"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twpayne%2Fgo-xmlstruct","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twpayne%2Fgo-xmlstruct/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twpayne%2Fgo-xmlstruct/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twpayne%2Fgo-xmlstruct/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/twpayne","download_url":"https://codeload.github.com/twpayne/go-xmlstruct/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247622983,"owners_count":20968575,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["generator","go","golang","schema","struct","xml","xsd"],"created_at":"2024-08-01T13:01:19.849Z","updated_at":"2025-04-07T09:19:37.003Z","avatar_url":"https://github.com/twpayne.png","language":"Go","readme":"# go-xmlstruct\n\n[![PkgGoDev](https://pkg.go.dev/badge/github.com/twpayne/go-xmlstruct)](https://pkg.go.dev/github.com/twpayne/go-xmlstruct)\n\nGenerate Go structs from multiple XML documents.\n\n## What does go-xmlstruct do and why should I use it?\n\ngo-xmlstruct generates Go structs from XML documents. Alternatively put,\ngo-xmlstruct infers XML schemas from one or more example XML documents. For\nexample, given [this XML\ndocument](https://github.com/twpayne/go-xmlstruct/blob/master/internal/tests/rss/testdata/sample-rss-2.xml),\ngo-xmlstruct generates [this Go source\ncode](https://github.com/twpayne/go-xmlstruct/blob/master/internal/tests/rss/rss.gen.go).\n\nCompared to existing Go struct generators like\n[zek](https://github.com/miku/zek),\n[XMLGen](https://github.com/dutchcoders/XMLGen), and\n[chidley](https://github.com/gnewton/chidley), go-xmlstruct:\n\n* Takes multiple XML documents as input.\n* Generates field types of `bool`, `int`, `string`, or `time.Time` as\n  appropriate.\n* Creates named types for all elements.\n* Handles optional attributes and elements.\n* Handles repeated attributes and elements.\n* Ignores empty chardata.\n* Provides a CLI for simple use.\n* Usable as a Go package for advanced use, including configurable field naming.\n\ngo-xmlstruct is useful for quick-and-dirty unmarshalling of arbitrary XML\ndocuments, especially when you have no schema or the schema is extremely complex\nand you want something that \"just works\" with the documents you have.\n\nNote the [bug in Go's `encoding/xml`](https://pkg.go.dev/encoding/xml#pkg-note-BUG):\n\n\u003e Mapping between XML elements and data structures is inherently flawed: an XML\n\u003e element is an order-dependent collection of anonymous values, while a data\n\u003e structure is an order-independent collection of named values. See\n\u003e encoding/json for a textual representation more suitable to data structures.\n\n## Install\n\nInstall the `goxmlstruct` CLI with:\n\n```console\n$ go install github.com/twpayne/go-xmlstruct/cmd/goxmlstruct@latest\n```\n\n## Example\n\nFeed `goxmlstruct` the simple XML document:\n\n```xml\n\u003cparent\u003e\n  \u003cchild flag=\"true\"\u003e\n    text\n  \u003c/child\u003e\n\u003c/parent\u003e\n```\n\nby running:\n\n```console\n$ echo '\u003cparent\u003e\u003cchild flag=\"true\"\u003etext\u003c/child\u003e\u003c/parent\u003e' | goxmlstruct\n```\n\nThis produces the output:\n\n```go\n// Code generated by goxmlstruct. DO NOT EDIT.\n\npackage main\n\ntype Parent struct {\n        Child struct {\n                Flag     bool   `xml:\"flag,attr\"`\n                CharData string `xml:\",chardata\"`\n        } `xml:\"child\"`\n}\n```\n\nThis demonstrates:\n\n* A Go struct is generated from the structure of the input XML document.\n* Attributes, child elements, and chardata are all considered.\n* Field names are generated automatically.\n* Field types are detected automatically.\n\nFor a full list of options to the `goxmlstruct` CLI run:\n\n```console\n$ goxmlstruct -help\n```\n\nYou can run a more advanced example with:\n\n```console\n$ git clone https://github.com/twpayne/go-xmlstruct.git\n$ cd go-xmlstruct\n$ goxmlstruct internal/tests/gpx/testdata/*.gpx\n```\n\nThis demonstrates generating a Go struct from multiple complex XML documents.\n\nFor an example of configurable field naming and named types by using\ngo-xmlstruct as a package, see\n[`internal/tests/rss/rss_test.go`](https://github.com/twpayne/go-xmlstruct/blob/master/internal/tests/rss/rss_test.go).\n\nFor an example of a complex schema, see\n[`internal/tests/aixm/aixm_test.go`](https://github.com/twpayne/go-xmlstruct/blob/master/internal/tests/aixm/aixm_test.go).\n\n## How does go-xmlstruct work?\n\nSimilar to [go-jsonstruct](https://github.com/twpayne/go-jsonstruct), go-xmlstruct consists of two phases:\n\n1. Firstly, go-xmlstruct explores all input XML documents to determine their\n   structure. It gathers statistics on the types used for each attribute,\n   chardata, and child element.\n2. Secondly, go-xmlstruct generates a Go struct based on the observed structure\n   using the gathered statistics to determine the type of each field.\n\n## License\n\nMIT","funding_links":[],"categories":["Go"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwpayne%2Fgo-xmlstruct","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftwpayne%2Fgo-xmlstruct","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwpayne%2Fgo-xmlstruct/lists"}