{"id":14984970,"url":"https://github.com/fullstackplayer/ts-xml-parser","last_synced_at":"2025-08-09T14:23:37.925Z","repository":{"id":46547344,"uuid":"345610553","full_name":"FullStackPlayer/ts-xml-parser","owner":"FullStackPlayer","description":"A better xml parser written in pure typescript and works well with deno.","archived":false,"fork":false,"pushed_at":"2023-05-11T10:36:59.000Z","size":92,"stargazers_count":12,"open_issues_count":4,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-10T23:14:03.900Z","etag":null,"topics":["deno","typescript","xml"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/FullStackPlayer.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":"2021-03-08T10:04:42.000Z","updated_at":"2024-04-30T08:47:28.000Z","dependencies_parsed_at":"2024-06-21T20:18:40.575Z","dependency_job_id":"4e6ede18-71b5-429c-bd48-708d578c2da5","html_url":"https://github.com/FullStackPlayer/ts-xml-parser","commit_stats":{"total_commits":5,"total_committers":2,"mean_commits":2.5,"dds":"0.19999999999999996","last_synced_commit":"b7e21b3d1b83225c635c7188c837d60d9de5ef67"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FullStackPlayer%2Fts-xml-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FullStackPlayer%2Fts-xml-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FullStackPlayer%2Fts-xml-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FullStackPlayer%2Fts-xml-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FullStackPlayer","download_url":"https://codeload.github.com/FullStackPlayer/ts-xml-parser/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248312135,"owners_count":21082638,"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":["deno","typescript","xml"],"created_at":"2024-09-24T14:10:00.410Z","updated_at":"2025-04-10T23:14:09.714Z","avatar_url":"https://github.com/FullStackPlayer.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ts-xml-parser\nA better xml parser written in pure typescript and works well with both node and deno.\n\n# Import to your project\n\n### For Node.js\nInstall it first:\n~~~bash\n// pay attention to the package name 'fsp-xml-parser'\nnpm install fsp-xml-parser\n// or\nyarn add fsp-xml-parser\n~~~\n\nThen import it:\n~~~js\n// CommonJS\nconst { parse } = require('fsp-xml-parser')\n// ES Module\n// In nodejs, you need bundlers(such as webpack/parcel...) support for now, this line of code couldn't run in nodejs directly.\n// But if typescript is your good friend, this is the right way.\nimport { parse } from 'fsp-xml-parser'\n~~~\n\n### For Deno\n~~~ts\n// remote import in Deno\nimport parse from \"https://denopkg.com/FullStackPlayer/ts-xml-parser/mod.ts\"\n// latest update: now you can import from deno.land\nimport parse from \"https://deno.land/x/ts_xml_parser/mod.ts\"\n// local import in Deno\nimport parse from \"path/to/parser.ts\"\n~~~\n\n# Usage\n\nSimple:\n~~~ts\nlet xml = `\n\u003c?xml version=\"1.0\" encoding=\"utf-8\" ?\u003e \n\u003ctagA\u003e\u003c/tagA\u003e\n`\nlet parsed = parse(xml)\n// parsed:\n// {\n//    \"declaration\": {\n//        \"attributes\": {\n//            \"version\": \"1.0\",\n//            \"encoding\": \"utf-8\"\n//        }\n//    },\n//    \"root\": {\n//        \"name\": \"tagA\"\n//    }\n//}\n~~~\n\nNamespace:\n~~~ts\nlet xml = `\n\u003c?xml version=\"1.0\" encoding=\"utf-8\" ?\u003e \n\u003cpropfind xmlns=\"DAV:\" xmlns:R=\"RES:\"\u003e\n    \u003cR:allprop/\u003e\n\u003c/propfind\u003e\n`\nlet parsed = parse(xml,true)    // true means prefixing namespace before tag name\n// parsed:\n// {\n//     \"declaration\": {\n//         \"attributes\": {\n//             \"version\": \"1.0\",\n//             \"encoding\": \"utf-8\"\n//         }\n//     },\n//     \"root\": {\n//         \"name\": \"DAV:propfind\",\n//         \"attributes\": {\n//             \"xmlns\": \"DAV:\",\n//             \"xmlns:R\": \"RES:\"\n//         },\n//         \"children\": [\n//             {\n//                 \"name\": \"RES:allprop\"\n//             }\n//         ]\n//     }\n// }\n~~~\n\nContent:\n~~~ts\nlet xml = `\n\u003c?xml version=\"1.0\" encoding=\"utf-8\" ?\u003e \n\u003ctagA\u003e\n    abc\u003c![CDATA[123一二三]]\u003e\n\u003c/tagA\u003e\n`\nlet parsed = parse(xml)\n// parsed:\n// {\n//     \"declaration\": {\n//         \"attributes\": {\n//             \"version\": \"1.0\",\n//             \"encoding\": \"utf-8\"\n//         }\n//     },\n//     \"root\": {\n//         \"name\": \"tagA\",\n//         \"content\": \"abc\u003c![CDATA[123一二三]]\u003e\"\n//     }\n// }\n~~~\n\nMixed Content (a node owns text content and child nodes at the same time):\n~~~ts\nlet xml = `\n\u003c?xml version=\"1.0\" encoding=\"utf-8\" ?\u003e\n\u003cfather\u003e\n    I have a son named John\u003cfullname\u003eJohnson\u003c/fullname\u003e.\n\u003c/father\u003e\n`\nlet parsed = parse(xml)\n// parsed:\n// {\n//     \"declaration\": {\n//         \"attributes\": {\n//             \"version\": \"1.0\",\n//             \"encoding\": \"utf-8\"\n//         }\n//     },\n//     \"root\": {\n//         \"name\": \"father\",\n//         \"children\": [\n//             {\n//                 \"name\": \"fullname\",\n//                 \"content\": \"Johnson\"\n//             }\n//         ],\n//         \"content\": \"I have a son named John.\"\n//     }\n// }\n~~~\n\nDeep Structure:\n~~~ts\nlet xml = `\n\u003c?xml version=\"1.0\" encoding=\"utf-8\" ?\u003e\n\u003cChina\u003e\n    \u003cHenan\u003e\u003c/Henan\u003e\n    \u003cShandong\u003e\n        \u003cJinan alias=\"Quancheng\"\u003e\n            \u003cLixia /\u003e\n            \u003cTianqiao\u003e\n                There is a big train station\u003cstation type=\"train\"\u003eTianqiao Station\u003c/station\u003e.\n            \u003c/Tianqiao\u003e\n        \u003c/Jinan\u003e\n    \u003c/Shandong\u003e\n\u003c/China\u003e\n`\nlet parsed = parse(xml)\n// parsed\n// {\n//     \"declaration\": {\n//         \"attributes\": {\n//             \"version\": \"1.0\",\n//             \"encoding\": \"utf-8\"\n//         }\n//     },\n//     \"root\": {\n//         \"name\": \"China\",\n//         \"children\": [\n//             {\n//                 \"name\": \"Henan\"\n//             },\n//             {\n//                 \"name\": \"Shandong\",\n//                 \"children\": [\n//                     {\n//                         \"name\": \"Jinan\",\n//                         \"attributes\": {\n//                             \"alias\": \"Quancheng\"\n//                         },\n//                         \"children\": [\n//                             {\n//                                 \"name\": \"Lixia\"\n//                             },\n//                             {\n//                                 \"name\": \"Tianqiao\",\n//                                 \"children\": [\n//                                     {\n//                                         \"name\": \"station\",\n//                                         \"attributes\": {\n//                                             \"type\": \"train\"\n//                                         },\n//                                         \"content\": \"Tianqiao Station\"\n//                                     }\n//                                 ],\n//                                 \"content\": \"There is a big train station.\"\n//                             }\n//                         ]\n//                     }\n//                 ]\n//             }\n//         ]\n//     }\n// }\n~~~\n\n# ATTENTION\n\n- If you have single `\\` characters in `\u003c![CDATA[]\u003e`, it will be ignored as an `escape character`, if you are sure a single `\\` is necessary, type `\\\\` instead.\n\n- `\u003c![CDATA[]]\u003e` can not be nested in a node content, if you really want to do that, encode your inner `\u003c![CDATA[]]\u003e` first, of course the receiver side should decode the content either.\n\n## Enjoy Yourself!","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffullstackplayer%2Fts-xml-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffullstackplayer%2Fts-xml-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffullstackplayer%2Fts-xml-parser/lists"}