{"id":19988605,"url":"https://github.com/guzba/smelly","last_synced_at":"2025-04-09T16:20:45.361Z","repository":{"id":261962216,"uuid":"769768764","full_name":"guzba/smelly","owner":"guzba","description":"Sometimes you have to parse XML 💩","archived":false,"fork":false,"pushed_at":"2024-12-22T07:37:26.000Z","size":125,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-09T16:20:40.227Z","etag":null,"topics":["nim","xml","xml-parser"],"latest_commit_sha":null,"homepage":"","language":"Nim","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/guzba.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":"2024-03-10T02:06:19.000Z","updated_at":"2024-12-22T07:37:07.000Z","dependencies_parsed_at":"2024-11-09T15:33:18.938Z","dependency_job_id":"16aa11b9-5c20-4286-8241-2130ea5a2325","html_url":"https://github.com/guzba/smelly","commit_stats":null,"previous_names":["guzba/smelly"],"tags_count":7,"template":false,"template_full_name":"treeform/nimtemplate","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guzba%2Fsmelly","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guzba%2Fsmelly/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guzba%2Fsmelly/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guzba%2Fsmelly/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/guzba","download_url":"https://codeload.github.com/guzba/smelly/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248065287,"owners_count":21041872,"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":["nim","xml","xml-parser"],"created_at":"2024-11-13T04:43:34.038Z","updated_at":"2025-04-09T16:20:45.330Z","avatar_url":"https://github.com/guzba.png","language":"Nim","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Smelly\n\n`nimble install smelly`\n\n[API reference](https://guzba.github.io/smelly/)\n\nSometimes you need to parse XML. Pinch your nose and get it over with.\n\nThis package is an alternative to Nim's standard library XML parser (std/xmlparser + std/xmltree).\n\n## Using Smelly\n\n```nim\nimport smelly\n\nlet s = \"\"\"\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\u003csvg viewBox=\"0 0 1200 400\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\"\u003e\n  \u003crect x=\"1\" y=\"1\" width=\"1198\" height=\"398\" fill=\"none\" stroke=\"blue\" stroke-width=\"2\" /\u003e\n  \u003cellipse transform=\"translate(900 200) rotate(-30)\" rx=\"250\" ry=\"100\" fill=\"none\" stroke=\"blue\" stroke-width=\"20\"  /\u003e\n  Some text content here\n\u003c/svg\u003e\n\"\"\"\n\nlet root = parseXml(s)\n\nfor child in root.children:\n  case child.kind:\n  of ElementNode:\n    echo child.tag, ' ', child.attributes[\"stroke-width\"]\n  of TextNode:\n    echo child.content\n```\n\n```\nrect 2\nellipse 20\nSome text content here\n```\n\n## Why create an alternative?\n\nAfter working with Nim's standard lib XML parsing for a while I have found some sources of frustration that I want to avoid.\n\nNim's std/xmltree uses `[]` on a node to access it's children and uses `.attr[]` to access attributes. This isn't so bad (it makes accessing deep into a node tree easy), however I always have to re-learn if `[]` accesses children or attributes after I've been away from XML parsing for a bit. With Smelly there is no amibguity, it's just `.children[]` and `.attributes[]`.\n\nEven more annoyingly, Nim's std/xml considers every single entity encoding (eg `\u0026lt;`) to be independent elements in the node tree instead of just a text encoding detail.\n\nIf an encoded entity is present:\n\n```nim\nimport std/xmlparser, std/xmltree\n\nlet root = parseXml(\"\u003cthing\u003e1 \u0026lt; 2\u003c/thing\u003e\")\necho root.tag # thing\necho root.len # 4 ?????\necho '\"', root[0], '\"' # \"1 \" ?????\n```\n\nAnd if an encoded entity is not present:\n\n```nim\nimport std/xmlparser, std/xmltree\n\nlet root = parseXml(\"\u003cthing\u003e1 or 2\u003c/thing\u003e\")\necho root.tag # thing\necho root.len # 1\necho '\"', root[0], '\"' # \"1 or 2\"\n```\nThis drastic difference in behavior based on the presence of an encoded entity is not cool with me.\n\nHere is how Smelly handles this:\n\n```nim\nimport smelly\n\nlet root = parseXml(\"\u003cthing\u003e1 \u0026lt; 2\u003c/thing\u003e\")\necho root.tag # thing\necho root.children.len # 1\necho '\"', root.children[0].content, '\"' # \"1 \u003c 2\"\n```\n\nAnd if an encoded entity is not present:\n\n```nim\nimport smelly\n\nlet root = parseXml(\"\u003cthing\u003e1 or 2\u003c/thing\u003e\")\necho root.tag # thing\necho root.children.len # 1\necho '\"', root.children[0].content, '\"' # \"1 or 2\"\n```\n\n## Performance\n\nSmelly is between 2x and 7x faster than `std/xmlparser` depending on the XML input.\n\nSee `tests/bench.nim` to test this for yourself.\n\n## Testing\n\n`nimble test`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguzba%2Fsmelly","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fguzba%2Fsmelly","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguzba%2Fsmelly/lists"}