{"id":50902988,"url":"https://github.com/stacksjs/ts-xml","last_synced_at":"2026-06-16T04:31:33.607Z","repository":{"id":343839761,"uuid":"1179350192","full_name":"stacksjs/ts-xml","owner":"stacksjs","description":"A performant, dependency-free XML parser, builder, and validator.","archived":false,"fork":false,"pushed_at":"2026-06-03T05:45:10.000Z","size":497,"stargazers_count":3,"open_issues_count":2,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-03T07:28:36.311Z","etag":null,"topics":["builder","parser","typescript","validator","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/stacksjs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":["stacksjs","chrisbbreuer"],"open_collective":"stacksjs"}},"created_at":"2026-03-12T00:09:47.000Z","updated_at":"2026-05-27T14:35:49.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/stacksjs/ts-xml","commit_stats":null,"previous_names":["stacksjs/ts-xml"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/stacksjs/ts-xml","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stacksjs%2Fts-xml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stacksjs%2Fts-xml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stacksjs%2Fts-xml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stacksjs%2Fts-xml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stacksjs","download_url":"https://codeload.github.com/stacksjs/ts-xml/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stacksjs%2Fts-xml/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34391702,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-16T02:00:06.860Z","response_time":126,"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":["builder","parser","typescript","validator","xml"],"created_at":"2026-06-16T04:31:32.474Z","updated_at":"2026-06-16T04:31:33.602Z","avatar_url":"https://github.com/stacksjs.png","language":"TypeScript","funding_links":["https://github.com/sponsors/stacksjs","https://github.com/sponsors/chrisbbreuer","https://opencollective.com/stacksjs"],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\u003cimg src=\".github/art/cover.jpg\" alt=\"Social Card of this repo\"\u003e\u003c/p\u003e\n\n[![npm version][npm-version-src]][npm-version-href]\n[![GitHub Actions][github-actions-src]][github-actions-href]\n[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)\n\u003c!-- [![npm downloads][npm-downloads-src]][npm-downloads-href] --\u003e\n\u003c!-- [![Codecov][codecov-src]][codecov-href] --\u003e\n\n# ts-xml\n\nA fast, dependency-free XML parser, builder, and validator for TypeScript and Bun. Character-by-character parsing with `charCodeAt` comparisons for maximum performance.\n\n## Features\n\n- **Zero Dependencies** - only Bun as a runtime\n- **XMLParser** - parse XML strings to JavaScript objects\n- **XMLBuilder** - build XML strings from JavaScript objects\n- **XMLValidator** - validate XML structure with detailed error reporting\n- **Entity Handling** - XML, HTML, numeric, and hex entity decoding/encoding\n- **Namespace Support** - optional namespace prefix removal\n- **Preserve Order** - array-based output to maintain element ordering\n- **Stop Nodes** - skip parsing of specific tag contents\n- **Unpaired Tags** - support for HTML-style void elements (e.g., `\u003cbr\u003e`, `\u003chr\u003e`)\n- **CDATA \u0026 Comments** - optionally capture CDATA sections and comments as properties\n- **Processing Instructions** - capture `\u003c?xml?\u003e` declarations and custom PIs\n- **Value Parsing** - automatic number, boolean, hex, and scientific notation parsing\n- **Custom Processors** - tag value, attribute value, and tag name transformation callbacks\n- **Fully Typed** - complete TypeScript type definitions\n\n## Get Started\n\n### Installation\n\n```bash\nbun install ts-xml\n```\n\n### Parsing XML\n\n```ts\nimport { XMLParser } from 'ts-xml'\n\nconst parser = new XMLParser()\nconst result = parser.parse('\u003croot\u003e\u003citem\u003eHello\u003c/item\u003e\u003c/root\u003e')\n// { root: { item: 'Hello' } }\n```\n\n### Parsing with Attributes\n\n```ts\nimport { XMLParser } from 'ts-xml'\n\nconst parser = new XMLParser({ ignoreAttributes: false })\nconst result = parser.parse('\u003cbook isbn=\"978-0-123\"\u003e\u003ctitle\u003eXML Guide\u003c/title\u003e\u003c/book\u003e')\n// { book: { '@_isbn': '978-0-123', title: 'XML Guide' } }\n```\n\n### Building XML\n\n```ts\nimport { XMLBuilder } from 'ts-xml'\n\nconst builder = new XMLBuilder({ format: true, indentBy: '  ' })\nconst xml = builder.build({\n  root: {\n    item: ['one', 'two', 'three'],\n  },\n})\n```\n\n### Validating XML\n\n```ts\nimport { XMLValidator } from 'ts-xml'\n\nconst result = XMLValidator('\u003croot\u003e\u003cchild/\u003e\u003c/root\u003e')\nif (result === true) {\n  console.log('Valid XML')\n}\nelse {\n  console.log(`Error: ${result.err.msg} at line ${result.err.line}`)\n}\n```\n\n### Preserve Element Order\n\n```ts\nimport { XMLParser, XMLBuilder } from 'ts-xml'\n\nconst parser = new XMLParser({ preserveOrder: true })\nconst ordered = parser.parse('\u003croot\u003e\u003ca\u003e1\u003c/a\u003e\u003cb\u003e2\u003c/b\u003e\u003ca\u003e3\u003c/a\u003e\u003c/root\u003e')\n// Maintains original element order as arrays\n\nconst builder = new XMLBuilder({ preserveOrder: true })\nconst xml = builder.build(ordered) // Round-trips correctly\n```\n\n## Configuration\n\n### Parser Options\n\n| Option | Type | Default | Description |\n|--------|------|---------|-------------|\n| `attributeNamePrefix` | `string` | `\"@_\"` | Prefix for attribute names |\n| `attributesGroupName` | `string \\| false` | `false` | Group attributes under this key |\n| `textNodeName` | `string` | `\"#text\"` | Property name for text content |\n| `ignoreAttributes` | `boolean` | `true` | Skip attribute parsing |\n| `removeNSPrefix` | `boolean` | `false` | Strip namespace prefixes |\n| `allowBooleanAttributes` | `boolean` | `false` | Allow attributes without values |\n| `alwaysCreateTextNode` | `boolean` | `false` | Always create text node property |\n| `trimValues` | `boolean` | `true` | Trim whitespace from values |\n| `parseTagValue` | `boolean` | `true` | Parse numbers/booleans from text |\n| `parseAttributeValue` | `boolean` | `false` | Parse numbers/booleans from attributes |\n| `processEntities` | `boolean` | `true` | Decode XML entities |\n| `htmlEntities` | `boolean` | `false` | Decode HTML entities |\n| `commentPropName` | `string \\| false` | `false` | Property name for comments |\n| `cdataPropName` | `string \\| false` | `false` | Property name for CDATA sections |\n| `piPropName` | `string \\| false` | `false` | Property name for processing instructions |\n| `preserveOrder` | `boolean` | `false` | Maintain element ordering |\n| `stopNodes` | `string[]` | `[]` | Tags whose content is not parsed |\n| `unpairedTags` | `string[]` | `[]` | Tags that don't need closing |\n| `numberParseOptions` | `NumberParseOptions` | `{ hex: true, leadingZeros: true, scientific: true }` | Number parsing behavior |\n\n### Builder Options\n\n| Option | Type | Default | Description |\n|--------|------|---------|-------------|\n| `attributeNamePrefix` | `string` | `\"@_\"` | Prefix for attribute names |\n| `textNodeName` | `string` | `\"#text\"` | Property name for text content |\n| `ignoreAttributes` | `boolean` | `false` | Skip attributes when building |\n| `format` | `boolean` | `false` | Pretty-print output |\n| `indentBy` | `string` | `\"  \"` | Indentation string |\n| `suppressEmptyNode` | `boolean` | `false` | Render empty nodes as self-closing |\n| `suppressBooleanAttributes` | `boolean` | `true` | Render boolean attributes without `=\"true\"` |\n| `processEntities` | `boolean` | `true` | Encode entities in output |\n| `preserveOrder` | `boolean` | `false` | Build from ordered format |\n\n## Benchmarks\n\nBenchmarked on Apple M3 Pro using [mitata](https://github.com/evanwashere/mitata), comparing against [fast-xml-parser](https://github.com/NaturalIntelligence/fast-xml-parser), [xml2js](https://github.com/Leonidas-from-XIV/node-xml2js), and [sax](https://github.com/isaacs/sax-js).\n\n### Parsing\n\n| Benchmark | ts-xml | fast-xml-parser | xml2js | sax |\n|-----------|--------|-----------------|--------|-----|\n| Simple XML | **344 ns** | 1.64 µs _(4.8x slower)_ | 2.03 µs | 885 ns |\n| Medium (3 products + attrs) | **6.67 µs** | 27.4 µs _(4.1x slower)_ | 18.0 µs | 12.3 µs |\n| Large (100 products) | **321 µs** | 1.16 ms _(3.6x slower)_ | 2.04 ms | 1.88 ms |\n| Very Large (1000 products) | **3.02 ms** | 13.0 ms _(4.3x slower)_ | 9.83 ms | 4.90 ms |\n| CDATA | **831 ns** | 2.89 µs _(3.5x slower)_ | 5.62 µs | 5.36 µs |\n| Deep nesting (50 levels) | **9.33 µs** | 59.1 µs _(6.3x slower)_ | 43.0 µs | 27.5 µs |\n| RSS Feed | **8.33 µs** | 40.4 µs _(4.9x slower)_ | 53.9 µs | 28.7 µs |\n| Entities | **2.28 µs** | 6.05 µs _(2.7x slower)_ | 9.42 µs | 6.42 µs |\n| Namespaces | **3.42 µs** | 14.4 µs _(4.2x slower)_ | 11.6 µs | 7.91 µs |\n\n### Building\n\n| Benchmark | ts-xml | fast-xml-parser | xml2js |\n|-----------|--------|-----------------|--------|\n| Small object | **1.61 µs** | 3.83 µs _(2.4x slower)_ | 8.60 µs |\n| Large (100 products) | **42.6 µs** | 118 µs _(2.8x slower)_ | 197 µs |\n| Formatted output | **1.67 µs** | 4.07 µs _(2.4x slower)_ | 8.05 µs |\n\n### Validation\n\n| Benchmark | ts-xml | fast-xml-parser |\n|-----------|--------|-----------------|\n| Valid XML | **3.30 µs** | 7.79 µs _(2.4x slower)_ |\n| Large valid (1000 products) | **1.39 ms** | 3.37 ms _(2.4x slower)_ |\n| Invalid XML (early exit) | **260 ns** | 591 ns _(2.3x slower)_ |\n\n### Round-trip\n\n| Benchmark | ts-xml | fast-xml-parser |\n|-----------|--------|-----------------|\n| Parse + Build (medium) | **9.15 µs** | 34.7 µs _(3.8x slower)_ |\n\n\u003e Run benchmarks yourself: `bun run bench`\n\n## Testing\n\n```bash\nbun test\n```\n\n724 tests across 6 test files covering parser, builder, validator, entities, and edge cases.\n\n## Changelog\n\nPlease see our [releases](https://github.com/stacksjs/ts-xml/releases) page for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.\n\n## Community\n\nFor help, discussion about best practices, or any other conversation that would benefit from being searchable:\n\n[Discussions on GitHub](https://github.com/stacksjs/ts-xml/discussions)\n\nFor casual chit-chat with others using this package:\n\n[Join the Stacks Discord Server](https://discord.gg/stacksjs)\n\n## Postcardware\n\n\"Software that is free, but hopes for a postcard.\" We love receiving postcards from around the world showing where Stacks is being used! We showcase them on our website too.\n\nOur address: Stacks.js, 12665 Village Ln #2306, Playa Vista, CA 90094, United States 🌎\n\n## Sponsors\n\nWe would like to extend our thanks to the following sponsors for funding Stacks development. If you are interested in becoming a sponsor, please reach out to us.\n\n- [JetBrains](https://www.jetbrains.com/)\n- [The Solana Foundation](https://solana.com/)\n\n## License\n\nThe MIT License (MIT). Please see [LICENSE](LICENSE.md) for more information.\n\nMade with 💙\n\n\u003c!-- Badges --\u003e\n[npm-version-src]: https://img.shields.io/npm/v/ts-xml?style=flat-square\n[npm-version-href]: https://npmjs.com/package/ts-xml\n[github-actions-src]: https://img.shields.io/github/actions/workflow/status/stacksjs/ts-xml/ci.yml?style=flat-square\u0026branch=main\n[github-actions-href]: https://github.com/stacksjs/ts-xml/actions?query=workflow%3Aci\n\n\u003c!-- [codecov-src]: https://img.shields.io/codecov/c/gh/stacksjs/ts-xml/main?style=flat-square\n[codecov-href]: https://codecov.io/gh/stacksjs/ts-xml --\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstacksjs%2Fts-xml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstacksjs%2Fts-xml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstacksjs%2Fts-xml/lists"}