{"id":13764118,"url":"https://github.com/sbabiv/xml2map","last_synced_at":"2025-05-10T17:31:39.917Z","repository":{"id":41429469,"uuid":"143763518","full_name":"sbabiv/xml2map","owner":"sbabiv","description":"XML to MAP converter written Golang","archived":false,"fork":false,"pushed_at":"2021-12-07T20:49:48.000Z","size":48,"stargazers_count":62,"open_issues_count":3,"forks_count":13,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-11-16T23:32:37.539Z","etag":null,"topics":["golang","map","xml","xml-parser","xml2map","xmtomap"],"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/sbabiv.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}},"created_at":"2018-08-06T17:51:46.000Z","updated_at":"2024-09-19T01:00:34.000Z","dependencies_parsed_at":"2022-09-21T08:39:30.130Z","dependency_job_id":null,"html_url":"https://github.com/sbabiv/xml2map","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbabiv%2Fxml2map","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbabiv%2Fxml2map/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbabiv%2Fxml2map/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbabiv%2Fxml2map/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sbabiv","download_url":"https://codeload.github.com/sbabiv/xml2map/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253453353,"owners_count":21911082,"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":["golang","map","xml","xml-parser","xml2map","xmtomap"],"created_at":"2024-08-03T15:01:14.419Z","updated_at":"2025-05-10T17:31:39.692Z","avatar_url":"https://github.com/sbabiv.png","language":"Go","readme":"[![Build Status](https://travis-ci.org/sbabiv/xml2map.svg?branch=master)](https://travis-ci.org/sbabiv/xml2map)\n[![Coverage Status](https://coveralls.io/repos/github/sbabiv/xml2map/badge.svg?branch=master)](https://coveralls.io/github/sbabiv/xml2map?branch=master)\n[![Go Report Card](https://goreportcard.com/badge/github.com/sbabiv/xml2map)](https://goreportcard.com/report/github.com/sbabiv/xml2map)\n[![GoDoc](https://godoc.org/github.com/sbabiv/xml2map?status.svg)](https://godoc.org/github.com/sbabiv/xml2map)\n[![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/avelino/awesome-go#xml)\n\n# xml2map\nXML to MAP converter written Golang\n\nSometimes there is a need for the representation of previously unknown structures. Such a universal representation is usually a string in the form of JSON, XML, or the structure of data map. similar to the map[string]interface{} or map[interface{}]interface{}.\n\nThis is a converter from the old XML format to map[string]interface{} Golang\n\nFor example, the map[string]interface{} can be used as a universal type in template generation. Golang \"text/template\" and etc.\n\n## Getting started\n\n#### 1. install \n\n``` sh\ngo get -u github.com/sbabiv/xml2map\n```\n\nOr, using dep:\n\n``` sh\ndep ensure -add github.com/sbabiv/xml2map\n```\n\n\n#### 2. use it\n\n```go\n\nfunc main() {\n\tdata := `\u003ccontainer uid=\"FA6666D9-EC9F-4DA3-9C3D-4B2460A4E1F6\" lifetime=\"2019-10-10T18:00:11\"\u003e\n\t\t\t\t\u003ccats\u003e\n\t\t\t\t\t\u003ccat\u003e\n\t\t\t\t\t\t\u003cid\u003eCDA035B6-D453-4A17-B090-84295AE2DEC5\u003c/id\u003e\n\t\t\t\t\t\t\u003cname\u003emoritz\u003c/name\u003e\n\t\t\t\t\t\t\u003cage\u003e7\u003c/age\u003e \t\n\t\t\t\t\t\t\u003citems\u003e\n\t\t\t\t\t\t\t\u003cn\u003e1293\u003c/n\u003e\n\t\t\t\t\t\t\t\u003cn\u003e1255\u003c/n\u003e\n\t\t\t\t\t\t\t\u003cn\u003e1257\u003c/n\u003e\n\t\t\t\t\t\t\u003c/items\u003e\n\t\t\t\t\t\u003c/cat\u003e\n\t\t\t\t\t\u003ccat\u003e\n\t\t\t\t\t\t\u003cid\u003e1634C644-975F-4302-8336-1EF1366EC6A4\u003c/id\u003e\n\t\t\t\t\t\t\u003cname\u003eoliver\u003c/name\u003e\n\t\t\t\t\t\t\u003cage\u003e12\u003c/age\u003e\n\t\t\t\t\t\u003c/cat\u003e\n\t\t\t\t\t\u003cdog color=\"gray\"\u003ehello\u003c/dog\u003e\n\t\t\t\t\u003c/cats\u003e\n\t\t\t\t\u003ccolor\u003ewhite\u003c/color\u003e\n\t\t\t\t\u003ccity\u003eNY\u003c/city\u003e\n\t\t\t\u003c/container\u003e`\n\n\tdecoder := xml2map.NewDecoder(strings.NewReader(data))\n\tresult, err := decoder.Decode()\n\n\tif err != nil {\n\t\tfmt.Printf(\"%v\\n\", err)\n\t} else {\n\t\tfmt.Printf(\"%v\\n\", result)\n\t}\n\t\n\tv := result[\"container\"].\n\t\t(map[string]interface{})[\"cats\"].\n\t\t\t(map[string]interface{})[\"cat\"].\n\t\t\t\t([]map[string]interface{})[0][\"items\"].\n\t\t\t\t\t(map[string]interface{})[\"n\"].([]string)[1]\n\t\t\t\t\t\n\tfmt.Printf(\"n[1]: %v\\n\", v)\n}\n\n```\nif you want to use your custom prefixes use the \n\n```\nNewDecoderWithPrefix(reader io.Reader, attrPrefix, textPrefix string) *Decoder\n```\n[Go Playground](https://play.golang.org/p/_n35DRTxTYF)\n\n## Output\n\n```go\nmap[container:map[@uid:FA6666D9-EC9F-4DA3-9C3D-4B2460A4E1F6 @lifetime:2019-10-10T18:00:11 cats:map[cat:[map[id:CDA035B6-D453-4A17-B090-84295AE2DEC5 name:moritz age:7 items:map[n:[1293 1255 1257]]] map[id:1634C644-975F-4302-8336-1EF1366EC6A4 name:oliver age:12]] dog:map[@color:gray #text:hello]] color:white city:NY]]\n\nresult: 1255\n```\n\n## Benchmark\n\n\n```go\n$ go test -bench=. -benchmem\ngoos: darwin\ngoarch: amd64\npkg: github.com/sbabiv/xml2map\nBenchmarkDecoder-8         50000             29773 ns/op           15032 B/op        261 allocs/op\nPASS\nok      github.com/sbabiv/xml2map       1.805s\n```\n\n## Licence\n[MIT](https://opensource.org/licenses/MIT)\n\n## Author \nBabiv Sergey\n","funding_links":[],"categories":["XML","Libraries for creating HTTP middlewares"],"sub_categories":["Routers","路由器","创建http中间件的代码库"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsbabiv%2Fxml2map","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsbabiv%2Fxml2map","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsbabiv%2Fxml2map/lists"}