{"id":13760659,"url":"https://github.com/tamerh/xml-stream-parser","last_synced_at":"2025-10-30T19:49:46.243Z","repository":{"id":54532888,"uuid":"167265344","full_name":"tamerh/xml-stream-parser","owner":"tamerh","description":"XML stream parser for GO","archived":false,"fork":false,"pushed_at":"2024-02-03T08:24:08.000Z","size":189,"stargazers_count":105,"open_issues_count":0,"forks_count":14,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-11-16T17:41:17.288Z","etag":null,"topics":["go","parser","xml","xml-deserialization","xml-parsing","xml-stream-parser"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tamerh.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":"2019-01-23T22:41:07.000Z","updated_at":"2024-10-01T18:59:14.000Z","dependencies_parsed_at":"2024-06-18T16:45:20.744Z","dependency_job_id":"db336d13-8015-43b3-b509-6166663d1a8a","html_url":"https://github.com/tamerh/xml-stream-parser","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tamerh%2Fxml-stream-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tamerh%2Fxml-stream-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tamerh%2Fxml-stream-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tamerh%2Fxml-stream-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tamerh","download_url":"https://codeload.github.com/tamerh/xml-stream-parser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253409970,"owners_count":21903996,"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":["go","parser","xml","xml-deserialization","xml-parsing","xml-stream-parser"],"created_at":"2024-08-03T13:01:15.738Z","updated_at":"2025-10-30T19:49:41.191Z","avatar_url":"https://github.com/tamerh.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# xml stream parser\n\nxml-stream-parser is xml parser for GO. It is efficient to parse large xml data with streaming fashion.\n\n## Usage\n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\u003cbookstore number=\"2\" loc=\"273456\"\u003e\n   \u003cbook\u003e\n      \u003ctitle\u003eThe Iliad and The Odyssey\u003c/title\u003e\n      \u003cprice\u003e12.95\u003c/price\u003e\n      \u003ccomments\u003e\n         \u003cuserComment rating=\"4\"\u003eBest translation I've read.\u003c/userComment\u003e\n         \u003cuserComment rating=\"2\"\u003eI like other versions better.\u003c/userComment\u003e\n      \u003c/comments\u003e\n   \u003c/book\u003e\n   \u003cbook\u003e\n      \u003ctitle\u003eAnthology of World Literature\u003c/title\u003e\n      \u003cprice\u003e24.95\u003c/price\u003e\n      \u003ccomments\u003e\n         \u003cuserComment rating=\"3\"\u003eNeeds more modern literature.\u003c/userComment\u003e\n         \u003cuserComment rating=\"4\"\u003eExcellent overview of world literature.\u003c/userComment\u003e\n      \u003c/comments\u003e\n   \u003c/book\u003e\n   \u003cjournal\u003e\n      \u003ctitle\u003eJournal of XML parsing\u003c/title\u003e\n      \u003cissue\u003e1\u003c/issue\u003e\n   \u003c/journal\u003e\n\u003c/bookstore\u003e\n```\n\n**Stream** over books and journals\n\n```go\nf, _ := os.Open(\"input.xml\")\nbr := bufio.NewReaderSize(f,65536)\nparser := xmlparser.NewXMLParser(br, \"book\", \"journal\")\n\nfor xml := range parser.Stream() {\n   fmt.Println(xml.Childs[\"title\"][0].InnerText)\n   if xml.Name == \"book\" {\n      fmt.Println(xml.Childs[\"comments\"][0].Childs[\"userComment\"][0].Attrs[\"rating\"])\n      fmt.Println(xml.Childs[\"comments\"][0].Childs[\"userComment\"][0].InnerText)\n   }\n}\n```\n\n**Skip** tags for speed\n\n```go\nparser := xmlparser.NewXMLParser(br, \"book\").SkipElements([]string{\"price\", \"comments\"})\n```\n\n**Attributes** only\n\n```go\nparser := xmlparser.NewXMLParser(br, \"bookstore\", \"book\").ParseAttributesOnly(\"bookstore\")\n```\n\n**Error** handlings\n\n```go\nfor xml := range parser.Stream() {\n   if xml.Err !=nil {\n      // handle error\n   }\n}\n```\n\n**Progress** of parsing\n\n```go\n// total byte read to calculate the progress of parsing\nparser.TotalReadSize\n```\n\n**Xpath** query provides alternative to default fast access for different usecases \n```go\n\nparser := xmlparser.NewXMLParser(bufreader, \"bookstore\").EnableXpath()\n\nfor xml := range p.Stream() {\n   // select books \n   xml.SelectElements(\"//book\")\n   xml.SelectElements(\"./book\")\n   xml.SelectElements(\"book\")\n   // select titles\n   xml.SelectElements(\"./book/title\")\n   // select book with price condition\n   xml.SelectElements(\"//book[price\u003e=20.95]\"))\n   //comments with rating 4\n   xml.SelectElements(\"//book/comments/userComment[@rating='4']\")\n}\n// for evaluate function or reuse existing xpath expression\n// sum of all the book price\nexpr, err := p.CompileXpath(\"sum(//book/price)\")\nprice := expr.Evaluate(p.CreateXPathNavigator(xml)).(float64)\n\n```\nxpath functionality implemented via [xpath](https://github.com/antchfx/xpath) library check more \nexamples in its documentation\n\nIf you interested check also [json parser](https://github.com/tamerh/jsparser) which works similarly\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftamerh%2Fxml-stream-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftamerh%2Fxml-stream-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftamerh%2Fxml-stream-parser/lists"}