{"id":24226660,"url":"https://github.com/clipcrow/xmlp","last_synced_at":"2025-12-11T21:04:43.844Z","repository":{"id":39578277,"uuid":"302866935","full_name":"clipcrow/xmlp","owner":"clipcrow","description":"XML Parser for Deno","archived":false,"fork":false,"pushed_at":"2024-10-18T03:42:16.000Z","size":68,"stargazers_count":14,"open_issues_count":2,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-13T14:19:53.077Z","etag":null,"topics":["deno","pull-parser","sax-parser","typescript","xml"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/clipcrow.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":"2020-10-10T09:37:43.000Z","updated_at":"2025-05-10T04:45:24.000Z","dependencies_parsed_at":"2024-08-25T12:45:22.108Z","dependency_job_id":"5e185af4-e771-48a6-8843-a80cdd697c84","html_url":"https://github.com/clipcrow/xmlp","commit_stats":null,"previous_names":["masataka/xmlp"],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/clipcrow/xmlp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clipcrow%2Fxmlp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clipcrow%2Fxmlp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clipcrow%2Fxmlp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clipcrow%2Fxmlp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/clipcrow","download_url":"https://codeload.github.com/clipcrow/xmlp/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clipcrow%2Fxmlp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275359682,"owners_count":25450625,"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","status":"online","status_checked_at":"2025-09-16T02:00:10.229Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["deno","pull-parser","sax-parser","typescript","xml"],"created_at":"2025-01-14T09:16:25.212Z","updated_at":"2025-09-22T17:31:51.267Z","avatar_url":"https://github.com/clipcrow.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# XML Parser for Deno\n\n[![ci](https://github.com/m-kur/xmlp/workflows/ci/badge.svg)](https://github.com/m-kur/xmlp/actions)\n\nThis project is an XML parser implemented for Deno as simply as possible. Currently it supports SAX style and Pull style.\nI'm thinking of using it only in applications that run on Deno. However, there is very little code that depends on Deno, so it's easy to make it available in Node (I don't).\nIf you haven't programmed with Deno yet, give it a try. Very nice. See [Deno official](https://deno.land/).\n\n## SAXParser\n\nWhen using in SAX style, create an instance of the parser and register the listener in the same way as used in the EventEmitter of Node.\nThe XML to be parsed is specified by Deno.Reader, UINT8 array, or a character string.\n\n```typescript\nimport { SAXParser } from 'https://deno.land/x/xmlp/mod.ts';\n\n// create a SAX parser instance\nconst parser = new SAXParser();\n\n// add SAX event handlers\nparser.on('start_prefix_mapping', (ns, uri) =\u003e {\n    console.log(`mapping start ${ns}: ${uri}`);\n}).on('text', (text, element) =\u003e {\n    if (element.qName === 'm:comment') {\n        console.log(`${element.attributes[0].value}: ${text}`);\n    }\n});\n\n// run parser, input source is Deno.Reader or Uint8Array or string\nconst reader = await Deno.open('parser_test.xml');\nawait parser.parse(reader, 'shift_jis'); // 2nd param is optional, specifies your XML encoding.\n```\n\nSAX event listener register definitions are below.\n\n```typescript\ninterface SAXEvent {\n    start_document: () =\u003e void;\n    processing_instruction: (procInst: string) =\u003e void;\n    sgml_declaration: (sgmlDecl: string) =\u003e void;\n    text: (text: string, element: ElementInfo, cdata: boolean) =\u003e void;\n    doctype: (doctype: string) =\u003e void;\n    start_prefix_mapping: (ns: string, uri: string) =\u003e void;\n    start_element: (element: ElementInfo) =\u003e void;\n    comment: (comment: string) =\u003e void;\n    end_element: (element: ElementInfo) =\u003e void;\n    end_prefix_mapping: (ns: string, uri: string) =\u003e void;\n    end_document: () =\u003e void;\n    error: (error: XMLParseError) =\u003e void;\n}\n\nclass SAXParser {\n    on\u003cK extends keyof SAXEvent\u003e(event: K, listener: SAXEvent[K]): this {}\n}\n```\n\nYou can use \"SAXParser\" on Deno's stream i/o because this is a simple \"UnderlyingSink\u003cUint8Array\u003e\" impl.\nSee the [parser.ts](parser.ts) / SAXParser#parse() -\u003e #getWriter() -\u003e getStream() -\u003e write() chain.\n\n## PullParser\n\nI think it's more interesting to write the Pull style than the SAX. This Pull parser is implemented using the ES6 Generator / Iterator mechanism. However, the basic implementation is shared with that of the SAX parser.\n\nCurrently the Pull parser supports Uint8 arrays and strings, not Deno.Reader.\n\n```typescript\nimport { PullParser } from 'https://deno.land/x/xmlp/mod.ts';\n\n// create a pull parser instance\nconst parser = new PullParser();\n\n// create an ES6 generator\nconst uint8Array = await Deno.readFile('parser_test.xml');\nconst events = parser.parse(uint8Array /*, encoding */);\n\n// pull events, using iterator\nconst event = events.next();\nif (event.value) {\n    console.log(event.value.name);\n}\n\n// using spread operator\nconsole.log([...events].filter(({ name }) =\u003e {\n    return name === 'text';\n}).map(({ text, cdata }) =\u003e {\n    return cdata ? `\u003c![CDATA[${text}]]\u003e` : text;\n}));\n```\n\n## DOMParser\n\nWill be realized eventually.\n\n## JSDoc\n\nUsually all you need see is mod.ts, SAXParser class or PullParser class.\n\nhttps://doc.deno.land/https/deno.land/x/xmlp/mod.ts\n\n## Acknowledgments\n\nThe basic logic of this XML parser was obtained by reading the source code of [sax-js](https://github.com/isaacs/sax-js). Thanks.\n\n\n## License\n\nThe scripts and documentation in this project are released under the [MIT License](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclipcrow%2Fxmlp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclipcrow%2Fxmlp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclipcrow%2Fxmlp/lists"}