{"id":13511646,"url":"https://github.com/miku/zek","last_synced_at":"2026-02-27T00:05:07.710Z","repository":{"id":27032646,"uuid":"111842183","full_name":"miku/zek","owner":"miku","description":"Generate a Go struct from XML.","archived":false,"fork":false,"pushed_at":"2025-11-10T13:16:23.000Z","size":641,"stargazers_count":816,"open_issues_count":9,"forks_count":65,"subscribers_count":18,"default_branch":"master","last_synced_at":"2025-11-10T15:13:28.210Z","etag":null,"topics":["code-generation","hacktoberfest","xml"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/miku.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2017-11-23T19:03:11.000Z","updated_at":"2025-11-10T13:16:28.000Z","dependencies_parsed_at":"2024-04-24T22:30:45.049Z","dependency_job_id":"8f0ad837-299e-425c-b7fa-bf6e5334444a","html_url":"https://github.com/miku/zek","commit_stats":{"total_commits":276,"total_committers":5,"mean_commits":55.2,"dds":"0.025362318840579712","last_synced_commit":"8aa766b13dbda12e3177b7b24a3871687a06a2d5"},"previous_names":[],"tags_count":28,"template":false,"template_full_name":null,"purl":"pkg:github/miku/zek","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miku%2Fzek","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miku%2Fzek/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miku%2Fzek/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miku%2Fzek/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/miku","download_url":"https://codeload.github.com/miku/zek/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miku%2Fzek/sbom","scorecard":{"id":646850,"data":{"date":"2025-08-11","repo":{"name":"github.com/miku/zek","commit":"00a490a3335940e32237adb4dd68a9c7aa4c2d6c"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.2,"checks":[{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Maintained","score":1,"reason":"2 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 1","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Code-Review","score":0,"reason":"Found 1/28 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/code_quality.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/code_quality.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/miku/zek/code_quality.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/code_quality.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/miku/zek/code_quality.yml/master?enable=pin","Info:   0 out of   2 GitHub-owned GitHubAction dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: GNU General Public License v3.0: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Signed-Releases","score":0,"reason":"Project has not signed or included provenance with any releases.","details":["Warn: release artifact v0.1.28 not signed: https://api.github.com/repos/miku/zek/releases/210869182","Warn: release artifact v0.1.27 not signed: https://api.github.com/repos/miku/zek/releases/210719539","Warn: release artifact v0.1.26 not signed: https://api.github.com/repos/miku/zek/releases/182820435","Warn: release artifact v0.1.25 not signed: https://api.github.com/repos/miku/zek/releases/170269243","Warn: release artifact v0.1.24 not signed: https://api.github.com/repos/miku/zek/releases/146885163","Warn: release artifact v0.1.28 does not have provenance: https://api.github.com/repos/miku/zek/releases/210869182","Warn: release artifact v0.1.27 does not have provenance: https://api.github.com/repos/miku/zek/releases/210719539","Warn: release artifact v0.1.26 does not have provenance: https://api.github.com/repos/miku/zek/releases/182820435","Warn: release artifact v0.1.25 does not have provenance: https://api.github.com/repos/miku/zek/releases/170269243","Warn: release artifact v0.1.24 does not have provenance: https://api.github.com/repos/miku/zek/releases/146885163"],"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 3 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-21T12:21:50.864Z","repository_id":27032646,"created_at":"2025-08-21T12:21:50.864Z","updated_at":"2025-08-21T12:21:50.864Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29878283,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-26T23:51:21.483Z","status":"ssl_error","status_checked_at":"2026-02-26T23:50:46.793Z","response_time":89,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["code-generation","hacktoberfest","xml"],"created_at":"2024-08-01T03:01:03.248Z","updated_at":"2026-02-27T00:05:07.691Z","avatar_url":"https://github.com/miku.png","language":"Go","readme":"# zek\n\nZek is a **prototype** for creating a Go\n[struct](https://golang.org/ref/spec#Struct_types) from an XML document. The\nresulting struct works best for *reading* XML (see also\n[#14](https://github.com/miku/zek/issues/14)), to create XML, you might want to\nuse [something else](https://github.com/avelino/awesome-go#xml).\n\nIt was developed at [Leipzig University Library](https://github.com/ubleipzig) to shorten the\ntime to go from raw XML to a struct that allows to access XML data in Go\nprograms.\n\n\u003e Skip the fluff, just the code.\n\nGiven some [XML](https://raw.githubusercontent.com/miku/zek/master/fixtures/e.xml), run:\n\n```go\n$ curl -s https://raw.githubusercontent.com/miku/zek/master/fixtures/e.xml | zek -e\n// Rss was generated 2018-08-30 20:24:14 by tir on sol.\ntype Rss struct {\n    XMLName xml.Name `xml:\"rss\"`\n    Text    string   `xml:\",chardata\"`\n    Rdf     string   `xml:\"rdf,attr\"`\n    Dc      string   `xml:\"dc,attr\"`\n    Geoscan string   `xml:\"geoscan,attr\"`\n    Media   string   `xml:\"media,attr\"`\n    Gml     string   `xml:\"gml,attr\"`\n    Taxo    string   `xml:\"taxo,attr\"`\n    Georss  string   `xml:\"georss,attr\"`\n    Content string   `xml:\"content,attr\"`\n    Geo     string   `xml:\"geo,attr\"`\n    Version string   `xml:\"version,attr\"`\n    Channel struct {\n        Text          string `xml:\",chardata\"`\n        Title         string `xml:\"title\"`         // ESS New Releases (Display...\n        Link          string `xml:\"link\"`          // http://tinyurl.com/ESSNew...\n        Description   string `xml:\"description\"`   // New releases from the Ear...\n        LastBuildDate string `xml:\"lastBuildDate\"` // Mon, 27 Nov 2017 00:06:35...\n        Item          []struct {\n            Text        string `xml:\",chardata\"`\n            Title       string `xml:\"title\"`       // Surficial geology, Aberde...\n            Link        string `xml:\"link\"`        // https://geoscan.nrcan.gc....\n            Description string `xml:\"description\"` // Geological Survey of Cana...\n            Guid        struct {\n                Text        string `xml:\",chardata\"` // 304279, 306212, 306175, 3...\n                IsPermaLink string `xml:\"isPermaLink,attr\"`\n            } `xml:\"guid\"`\n            PubDate       string   `xml:\"pubDate\"`      // Fri, 24 Nov 2017 00:00:00...\n            Polygon       []string `xml:\"polygon\"`      // 64.0000 -98.0000 64.0000 ...\n            Download      string   `xml:\"download\"`     // https://geoscan.nrcan.gc....\n            License       string   `xml:\"license\"`      // http://data.gc.ca/eng/ope...\n            Author        string   `xml:\"author\"`       // Geological Survey of Cana...\n            Source        string   `xml:\"source\"`       // Geological Survey of Cana...\n            SndSeries     string   `xml:\"SndSeries\"`    // Bedford Institute of Ocea...\n            Publisher     string   `xml:\"publisher\"`    // Natural Resources Canada,...\n            Edition       string   `xml:\"edition\"`      // prelim., surficial data m...\n            Meeting       string   `xml:\"meeting\"`      // Geological Association of...\n            Documenttype  string   `xml:\"documenttype\"` // serial, open file, serial...\n            Language      string   `xml:\"language\"`     // English, English, English...\n            Maps          string   `xml:\"maps\"`         // 1 map, 5 maps, Publicatio...\n            Mapinfo       string   `xml:\"mapinfo\"`      // surficial geology, surfic...\n            Medium        string   `xml:\"medium\"`       // on-line; digital, digital...\n            Province      string   `xml:\"province\"`     // Nunavut, Northwest Territ...\n            Nts           string   `xml:\"nts\"`          // 066B, 095J; 095N; 095O; 0...\n            Area          string   `xml:\"area\"`         // Aberdeen Lake, Mackenzie ...\n            Subjects      string   `xml:\"subjects\"`\n            Program       string   `xml:\"program\"`       // GEM2: Geo-mapping for Ene...\n            Project       string   `xml:\"project\"`       // Rae Province Project Mana...\n            Projectnumber string   `xml:\"projectnumber\"` // 340521, 343202, 340557, 3...\n            Abstract      string   `xml:\"abstract\"`      // This new surficial geolog...\n            Links         string   `xml:\"links\"`         // Online - En ligne (PDF, 9...\n            Readme        string   `xml:\"readme\"`        // readme | https://geoscan....\n            PPIid         string   `xml:\"PPIid\"`         // 34532, 35096, 35438, 2563...\n        } `xml:\"item\"`\n    } `xml:\"channel\"`\n}\n```\n\n## Online\n\n* try online via WASM: [https://xml-to-go.github.io/](https://xml-to-go.github.io/), thanks [YaroslavPodorvanov](https://github.com/YaroslavPodorvanov)!\n* try it online at [https://blog.kowalczyk.info/tools/xmltogo/](https://blog.kowalczyk.info/tools/xmltogo/) -- thanks, [kjk](https://github.com/kjk)!\n\n## About\n\n[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)\n\nUpsides:\n\n* it works fine for non-recursive structures,\n* does not need XSD or DTD,\n* it is relatively convenient to access attributes, children and text,\n* will generate a single struct, which make for a quite compact representation,\n* simple user interface,\n* comments with examples,\n* schema inference across multiple files.\n\nDownsides:\n\n* experimental, early, buggy, unstable prototype,\n* no support for recursive types (similar to *Russian Doll* strategy, [[1](https://medbiq.org/std_specs/techguidelines/xmldesignguidelines.pdf#page=7)])\n* no type inference, everything is accessible as string (without a schema, type inference may fail if the type *guess* is wrong)\n\nBugs:\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.\n\nhttps://golang.org/pkg/encoding/xml/#pkg-note-BUG\n\nRelated projects:\n\n* https://github.com/bemasher/JSONGen\n* https://github.com/dutchcoders/XMLGen\n* https://github.com/gnewton/chidley\n* https://github.com/twpayne/go-xmlstruct\n\nAnd other [awesome XML utilities](https://github.com/avelino/awesome-go#xml).\n\nPresentations:\n\n* [Lightning talk about struct generators](https://gist.github.com/miku/39e4273d15abfd7e4297071338da3349) at [GoLab 2018](https://www.golab.io/)\n\n## Install\n\n```\n$ go install github.com/miku/zek/cmd/zek@latest\n```\n\nDebian and RPM packages:\n\n* https://github.com/miku/zek/releases\n\nIt's in [AUR](https://aur.archlinux.org/packages/zek-bin/), too.\n\n![](https://github.com/miku/zek/blob/master/docs/114391.png)\n\n## Usage\n\n```shell\n$ zek -h\n  -B    use a fixed banner string (e.g. for CI)\n  -C    emit less compact struct\n  -F    skip formatting\n  -I    use verbatim innerxml instead of chardata\n  -P string\n        if set, write out struct within a package with the given name\n  -S int\n        read at most this many tags, approximately (0=unlimited)\n  -c    emit more compact struct (noop, as this is the default since 0.1.7)\n  -d    debug output\n  -e    add comments with example\n  -j    add JSON tags\n  -m    omit empty Text fields\n  -max-examples int\n        limit number of examples (default 10)\n  -n string\n        use a different name for the top-level struct\n  -o string\n        if set, write to output file, not stdout\n  -p    write out an example program\n  -s    strict parsing and writing\n  -t string\n        emit struct for tag matching this name\n  -u    filter out duplicated examples\n  -version\n        show version\n  -x int\n        max chars for example (default 25)\n```\n\nExamples:\n\n```xml\n$ cat fixtures/a.xml\n\u003ca\u003e\u003c/a\u003e\n\n$ zek -C \u003c fixtures/a.xml\ntype A struct {\n    XMLName xml.Name `xml:\"a\"`\n    Text    string   `xml:\",chardata\"`\n}\n```\n\nDebug output dumps the internal tree as JSON to stdout.\n\n```json\n$ zek -d \u003c fixtures/a.xml\n{\"name\":{\"Space\":\"\",\"Local\":\"a\"}}\n```\n\nExample program:\n\n```go\npackage main\n\nimport (\n\t\"encoding/json\"\n\t\"encoding/xml\"\n\t\"fmt\"\n\t\"log\"\n\t\"os\"\n)\n\n// A was generated 2017-12-05 17:35:21 by tir on apollo.\ntype A struct {\n\tXMLName xml.Name `xml:\"a\"`\n\tText    string   `xml:\",chardata\"`\n}\n\nfunc main() {\n\tdec := xml.NewDecoder(os.Stdin)\n\tvar doc A\n\tif err := dec.Decode(\u0026doc); err != nil {\n\t\tlog.Fatal(err)\n\t}\n\tb, err := json.Marshal(doc)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\tfmt.Println(string(b))\n}\n\n$ zek -C -p \u003c fixtures/a.xml \u003e sample.go \u0026\u0026 go run sample.go \u003c fixtures/a.xml | jq . \u0026\u0026 rm sample.go\n{\n  \"XMLName\": {\n    \"Space\": \"\",\n    \"Local\": \"a\"\n  },\n  \"Text\": \"\"\n}\n```\n\nMore complex example:\n\n```go\n$ zek \u003c fixtures/d.xml\n// Root was generated 2019-06-11 16:27:04 by tir on hayiti.\ntype Root struct {\n        XMLName xml.Name `xml:\"root\"`\n        Text    string   `xml:\",chardata\"`\n        A       []struct {\n                Text string `xml:\",chardata\"`\n                B    []struct {\n                        Text string `xml:\",chardata\"`\n                        C    string `xml:\"c\"`\n                        D    string `xml:\"d\"`\n                } `xml:\"b\"`\n        } `xml:\"a\"`\n}\n\n$ zek -p \u003c fixtures/d.xml \u003e sample.go \u0026\u0026 go run sample.go \u003c fixtures/d.xml | jq . \u0026\u0026 rm sample.go\n{\n  \"XMLName\": {\n    \"Space\": \"\",\n    \"Local\": \"root\"\n  },\n  \"Text\": \"\\n\\n\\n\\n\",\n  \"A\": [\n    {\n      \"Text\": \"\\n  \\n  \\n\",\n      \"B\": [\n        {\n          \"Text\": \"\\n    \\n  \",\n          \"C\": \"Hi\",\n          \"D\": \"\"\n        },\n        {\n          \"Text\": \"\\n    \\n    \\n  \",\n          \"C\": \"World\",\n          \"D\": \"\"\n        }\n      ]\n    },\n    {\n      \"Text\": \"\\n  \\n\",\n      \"B\": [\n        {\n          \"Text\": \"\\n    \\n  \",\n          \"C\": \"Hello\",\n          \"D\": \"\"\n        }\n      ]\n    },\n    {\n      \"Text\": \"\\n  \\n\",\n      \"B\": [\n        {\n          \"Text\": \"\\n    \\n  \",\n          \"C\": \"\",\n          \"D\": \"World\"\n        }\n      ]\n    }\n  ]\n}\n```\n\nAnnotate with comments:\n\n```go\n$ zek -e \u003c fixtures/l.xml\n// Records was generated 2019-06-11 16:29:35 by tir on hayiti.\ntype Records struct {\n        XMLName xml.Name `xml:\"Records\"`\n        Text    string   `xml:\",chardata\"` // \\n\n        Xsi     string   `xml:\"xsi,attr\"`\n        Record  []struct {\n                Text   string `xml:\",chardata\"`\n                Header struct {\n                        Text       string `xml:\",chardata\"`\n                        Status     string `xml:\"status,attr\"`\n                        Identifier string `xml:\"identifier\"` // oai:ojs.localhost:article...\n                        Datestamp  string `xml:\"datestamp\"`  // 2009-06-24T14:48:23Z, 200...\n                        SetSpec    string `xml:\"setSpec\"`    // eppp:ART, eppp:ART, eppp:...\n                } `xml:\"header\"`\n                Metadata struct {\n                        Text    string `xml:\",chardata\"`\n                        Rfc1807 struct {\n                                Text           string   `xml:\",chardata\"`\n                                Xmlns          string   `xml:\"xmlns,attr\"`\n                                Xsi            string   `xml:\"xsi,attr\"`\n                                SchemaLocation string   `xml:\"schemaLocation,attr\"`\n                                BibVersion     string   `xml:\"bib-version\"`  // v2, v2, v2...\n                                ID             string   `xml:\"id\"`           // http://jou...\n                                Entry          string   `xml:\"entry\"`        // 2009-06-24...\n                                Organization   []string `xml:\"organization\"` // Proceeding...\n                                Title          string   `xml:\"title\"`        // Introducti...\n                                Type           string   `xml:\"type\"`\n                                Author         []string `xml:\"author\"`       // KRAMPEN, G..\n                                Copyright      string   `xml:\"copyright\"`    // Das Urhebe...\n                                OtherAccess    string   `xml:\"other_access\"` // url:http:/...\n                                Keyword        string   `xml:\"keyword\"`\n                                Period         []string `xml:\"period\"`\n                                Monitoring     string   `xml:\"monitoring\"`\n                                Language       string   `xml:\"language\"` // en, en, en, e...\n                                Abstract       string   `xml:\"abstract\"` // After a short...\n                                Date           string   `xml:\"date\"`     // 2009-06-22 12...\n                        } `xml:\"rfc1807\"`\n                } `xml:\"metadata\"`\n                About string `xml:\"about\"`\n        } `xml:\"Record\"`\n}\n```\n\n## Only consider a nested element\n\n```go\n$ zek -t metadata fixtures/z.xml\n// Metadata was generated 2019-06-11 16:33:26 by tir on hayiti.\ntype Metadata struct {\n        XMLName xml.Name `xml:\"metadata\"`\n        Text    string   `xml:\",chardata\"`\n        Dc      struct {\n                Text  string `xml:\",chardata\"`\n                Xmlns string `xml:\"xmlns,attr\"`\n                Title struct {\n                        Text  string `xml:\",chardata\"`\n                        Xmlns string `xml:\"xmlns,attr\"`\n                } `xml:\"title\"`\n                Identifier struct {\n                        Text  string `xml:\",chardata\"`\n                        Xmlns string `xml:\"xmlns,attr\"`\n                } `xml:\"identifier\"`\n                Rights struct {\n                        Text  string `xml:\",chardata\"`\n                        Xmlns string `xml:\"xmlns,attr\"`\n                        Lang  string `xml:\"lang,attr\"`\n                } `xml:\"rights\"`\n                AccessRights struct {\n                        Text  string `xml:\",chardata\"`\n                        Xmlns string `xml:\"xmlns,attr\"`\n                } `xml:\"accessRights\"`\n        } `xml:\"dc\"`\n}\n```\n\n## Inference across files\n\n```go\n$ zek fixtures/a.xml fixtures/b.xml fixtures/c.xml\n// A was generated 2017-12-05 17:40:14 by tir on apollo.\ntype A struct {\n\tXMLName xml.Name `xml:\"a\"`\n\tText    string   `xml:\",chardata\"`\n\tB       []struct {\n\t\tText string `xml:\",chardata\"`\n\t} `xml:\"b\"`\n}\n```\n\nThis is also useful, if you deal with archives containing XML files:\n\n```shell\n$ unzip -p 4082359.zip '*.xml' | zek -e\n```\n\nGiven a directory full of zip files, you can combined find, unzip and zek:\n\n```shell\n$ for i in $(find ftp/b571 -type f -name \"*zip\"); do unzip -p $i '*xml'; done | zek -e\n```\n\nAnother example (tarball with thousands of XML files, seemingly MARC):\n\n```shell\n$ tar -xOzf /tmp/20180725.125255.tar.gz | zek -e\n// OAIPMH was generated 2018-09-26 15:03:29 by tir on sol.\ntype OAIPMH struct {\n        XMLName        xml.Name `xml:\"OAI-PMH\"`\n        Text           string   `xml:\",chardata\"`\n        Xmlns          string   `xml:\"xmlns,attr\"`\n        Xsi            string   `xml:\"xsi,attr\"`\n        SchemaLocation string   `xml:\"schemaLocation,attr\"`\n        ListRecords    struct {\n                Text   string `xml:\",chardata\"`\n                Record struct {\n                        Text   string `xml:\",chardata\"`\n                        Header struct {\n                                Text       string `xml:\",chardata\"`\n                                Identifier struct {\n                                        Text string `xml:\",chardata\"` // aleph-pub:000000001, ...\n                                } `xml:\"identifier\"`\n                        } `xml:\"header\"`\n                        Metadata struct {\n                                Text   string `xml:\",chardata\"`\n                                Record struct {\n                                        Text           string `xml:\",chardata\"`\n                                        Xmlns          string `xml:\"xmlns,attr\"`\n                                        Xsi            string `xml:\"xsi,attr\"`\n                                        SchemaLocation string `xml:\"schemaLocation,attr\"`\n                                        Leader         struct\n                                                Text string `xml:\",chardata\"` // 00001nM2.01200024\n                                        } `xml:\"leader\"`\n                                        Controlfield []struct {\n                                                Text string `xml:\",chardata\"` // 00001nM2.01200024\n                                                Tag  string `xml:\"tag,attr\"`\n                                        } `xml:\"controlfield\"`\n                                        Datafield []struct {\n                                                Text     string `xml:\",chardata\"`\n                                                Tag      string `xml:\"tag,attr\"`\n                                                Ind1     string `xml:\"ind1,attr\"`\n                                                Ind2     string `xml:\"ind2,attr\"`\n                                                Subfield []struct {\n                                                        Text string `xml:\",chardata\"` // KM0000002\n                                                        Code string `xml:\"code,attr\"`\n                                                } `xml:\"subfield\"`\n                                        } `xml:\"datafield\"`\n                                } `xml:\"record\"`\n                        } `xml:\"metadata\"`\n                } `xml:\"record\"`\n        } `xml:\"ListRecords\"`\n}\n```\n\n## Generate a package\n\nIf you want in include generated file in the build process, e.g. with [go\ngenerate](https://go.dev/blog/generate), you may find `-P` and `-o`\nhelpful.\n\n```sh\n$ cat fixtures/b.xml\n\u003ca\u003e\u003cb\u003e\u003c/b\u003e\u003c/a\u003e\n```\n\nRun on the command line or via *go generate*:\n\n```sh\n$ zek -P mypkg -o data.go \u003c fixtures/b.xml\n```\n\nThis would write out the following in `data.go` file:\n\n```go\n// Code generated by zek; DO NOT EDIT.\n\npackage mypkg\n\nimport \"encoding/xml\"\n\n// A was generated 2021-09-16 11:23:06 by tir on trieste.\ntype A struct {\n        XMLName xml.Name `xml:\"a\"`\n        Text    string   `xml:\",chardata\"`\n        B       string   `xml:\"b\"`\n}\n```\n\nNote that any existing file will be overwritten, without any warning.\n\n## Use innerxml instead of chardata\n\nYou may want `chardata` or `innerxml` tag. Default is `chardata`, to use `innerxml` use the `-I` flag.\n\n```sh\n$ zek -B -I fixtures/d.xml\n// Root was generated automatically by zek 0.1.24. DO NOT EDIT.\ntype Root struct {\n        XMLName xml.Name `xml:\"root\"`\n        Text    string   `xml:\",innerxml\"`\n        A       []struct {\n                Text string `xml:\",innerxml\"`\n                B    []struct {\n                        Text string `xml:\",innerxml\"`\n                        C    string `xml:\"c\"`\n                        D    string `xml:\"d\"`\n                } `xml:\"b\"`\n        } `xml:\"a\"`\n}\n```\n\n## Misc\n\nAs a side effect, zek seems to be a useful for debugging. Example:\n\n* https://git.io/vbUNa\n\nThis record is emitted from a typical [OAI](https://www.openarchives.org/)\nserver ([OJS](https://pkp.sfu.ca/ojs/), not even uncommon), yet one can quickly\nspot the flaw in the structure.\n\nOver 30 different struct generated manually in the course of a few hours\n(around five minutes per source): https://git.io/vbTDo.\n\n-- Current extent leader: [1532](https://github.com/miku/zek/blob/master/fixtures/r.txt) lines struct\n\n","funding_links":[],"categories":["XML","Go","[](https://github.com/golang/go/wiki/CodeTools#code-generation-templating-and-generics)Code generation, Templating and Generics","Libraries for creating HTTP middlewares"],"sub_categories":["Routers","创建http中间件的代码库","Utility/Miscellaneous","路由器","[](https://github.com/golang/go/wiki/CodeTools#tools)Tools"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmiku%2Fzek","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmiku%2Fzek","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmiku%2Fzek/lists"}