{"id":14171,"library":"txml","title":"tXml Fast XML Parser","description":"tXml is a highly optimized and lightweight XML parser designed for high performance across various JavaScript environments, including Node.js, browsers, web workers, and serverless functions. Currently stable at version 5.2.1, the library maintains an active development pace with notable recent updates like the v4 and v5 series. Its core strength lies in its speed, significantly outperforming alternatives like `sax` or `xml2js`, and offering a measurable advantage over `fast-xml-parser` while maintaining a minimal footprint (1.6KB minified + gzipped). tXml distinguishes itself by providing a simple `txml.parse(xml)` API, robust error handling for malformed XML, comprehensive feature support including namespaces, CDATA, and stream processing, and generating an easily traversable DOM-like object. It also offers advanced features such as direct ID/class search on the XML string and simplification options similar to PHP's SimpleXML.","status":"active","version":"5.2.1","language":"javascript","source_language":"en","source_url":"https://github.com/TobiasNickel/tXml","tags":["javascript","xml","parser","dom","document","small","fast","simple","typescript"],"install":[{"cmd":"npm install txml","lang":"bash","label":"npm"},{"cmd":"yarn add txml","lang":"bash","label":"yarn"},{"cmd":"pnpm add txml","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Since v4, the `parse` function is a method of the main `txml` module object. It should be imported as a namespace (`import * as txml from 'txml'`) for ESM/TypeScript or via CommonJS `require` (`const txml = require('txml');`) for `txml.parse()` access.","wrong":"import { parse } from 'txml';","symbol":"txml.parse","correct":"import * as txml from 'txml';"},{"note":"The `transformStream` utility is a named export for Node.js stream processing. For smaller browser bundles, consider importing `txml/txml` or `txml/dist/txml` to explicitly exclude Node.js stream components.","wrong":"import * as txml from 'txml'; txml.transformStream;","symbol":"transformStream","correct":"import { transformStream } from 'txml';"},{"note":"The package provides TypeScript definitions. Common types like `XMLNode` for the parsed DOM structure are available as type imports.","wrong":"import { XMLNode } from 'txml';","symbol":"XMLNode","correct":"import type { XMLNode } from 'txml';"}],"quickstart":{"code":"import * as txml from 'txml';\n\nconst xmlString = `\n  <bookstore>\n    <!-- Best sellers -->\n    <book category=\"cooking\">\n      <title lang=\"en\">Everyday Italian</title>\n      <author>Giada De Laurentiis</author>\n      <year>2005</year>\n      <price>30.00</price>\n    </book>\n    <book category=\"children\">\n      <title lang=\"en\">Harry Potter</title>\n      <author>J.K. Rowling</author>\n      <year>2005</year>\n      <price>29.99</price>\n    </book>\n  </bookstore>\n`;\n\n// Basic parsing, returns an array of nodes\nconst parsedXml = txml.parse(xmlString);\nconsole.log('Parsed XML (basic):', JSON.stringify(parsedXml, null, 2));\n\n// Parsing with options: simplify and keep comments\nconst simplifiedXml = txml.parse(xmlString, {\n  simplify: true,\n  keepComments: true\n});\nconsole.log('Parsed XML (simplified & comments):', JSON.stringify(simplifiedXml, null, 2));\n\n// Accessing elements in the simplified structure\nconst books = simplifiedXml.bookstore.book;\nif (Array.isArray(books)) {\n  console.log('First book title (simplified):', books[0].title); \n} else if (books) {\n  console.log('Single book title (simplified):', books.title);\n} else {\n  console.log('No books found in simplified XML.');\n}\n\n// Example of using filter to find specific elements\nconst cookingBooks = txml.parse(xmlString, {\n  filter: (node) => node.tagName === 'book' && node.attributes?.category === 'cooking'\n});\nconsole.log('Cooking books (filtered):', JSON.stringify(cookingBooks, null, 2));\n","lang":"typescript","description":"Demonstrates basic synchronous XML parsing using `txml.parse`, including options for simplification and comment preservation, and accessing elements from the resulting DOM object. It also shows filtering for specific nodes."},"warnings":[{"fix":"Update import statements to `import * as txml from 'txml';` (ESM/TypeScript) or `const txml = require('txml');` (CommonJS), then use `txml.parse(xmlString, options);`.","message":"Major changes in module export structure were introduced in v4. The primary parsing function is now exclusively accessed via `txml.parse()`. Direct named imports for `parse` might no longer work as expected.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Migrate stream processing logic to use `transformStream`. Refer to documentation for updated usage patterns, including `for await` loops.","message":"The `parseStream` method was removed in v4, replaced by `transformStream` for Node.js stream processing.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"For smaller browser builds, import the core library via `import * as txml from 'txml/txml';` or `import * as txml from 'txml/dist/txml';` to explicitly exclude the stream components.","message":"Including `transformStream` in your bundle can increase its size, especially for browser applications, as it incorporates Node.js-specific code. It's often not needed client-side.","severity":"gotcha","affected_versions":">=4.0.0"},{"fix":"Pass `{ keepWhitespace: true }` to the `txml.parse()` options object if whitespace preservation is required.","message":"By default, `txml` discards whitespace (spaces, tabs, newlines) between elements. If significant whitespace needs to be preserved (e.g., in mixed content XML or for formatting), the `keepWhitespace` option must be explicitly set to `true`.","severity":"gotcha","affected_versions":">=4.0.1"},{"fix":"If strict HTML parsing behavior for `hr` and similar tags is required, review and adjust the `noChildNodes` option to customize self-closing element definitions.","message":"Since v4.0.1, HTML `hr` tags are treated as self-closing by default. This change might affect parsing behavior for specific HTML-like XML structures where an explicit closing `</hr>` tag was expected or handled differently.","severity":"gotcha","affected_versions":">=4.0.1"}],"env_vars":null,"search_vec":"'1.6':81 '5.2.1':34 'across':18 'activ':39 'advanc':122 'advantag':70 'also':120 'altern':61 'api':94 'browser':24 'cdata':106 'comprehens':101 'core':53 'current':30 'design':14 'develop':40 'direct':126 'distinguish':86 'document':145 'dom':116,144 'dom-lik':115 'easili':113 'environ':21 'error':96 'fast':2,73,147 'fast-xml-pars':72 'featur':102,123 'footprint':80 'function':29 'generat':111 'gzip':84 'handl':97 'high':8,16 'id/class':127 'includ':22,104 'javascript':20,141 'kb':82 'librari':36 'lie':55 'lightweight':11 'like':46,62,117 'maintain':37,77 'malform':99 'measur':69 'minifi':83 'minim':79 'namespac':105 'node.js':23 'notabl':43 'object':118 'offer':67,121 'optim':9 'option':135 'outperform':60 'pace':41 'parser':4,13,75,143 'perform':17 'php':138 'process':109 'provid':89 'recent':44 'robust':95 'sax':63 'search':128 'seri':51 'serverless':28 'signific':59 'similar':136 'simpl':91,148 'simplexml':140 'simplif':134 'small':146 'speed':58 'stabl':31 'stream':108 'strength':54 'string':132 'support':103 'travers':114 'txml':1,5,85 'txml.parse':92 'typescript':149 'updat':45 'v4':48 'v5':50 'various':19 'version':33 'web':25 'worker':26 'xml':3,12,74,93,100,131,142 'xml2js':65","created_at":"2026-04-20T01:58:18.043101+00:00","updated_at":"2026-04-20T01:58:18.043101+00:00","problems":[{"fix":"Ensure `txml` is imported as a namespace (`import * as txml from 'txml';`) or correctly required as a module (`const txml = require('txml');`), then access `parse` as a method (`txml.parse(...)`).","cause":"Incorrect import pattern for ESM/TypeScript, or trying to destructure `parse` directly from `require('txml')` in CommonJS after v4.0.0.","error":"TypeError: txml.parse is not a function"},{"fix":"Ensure `simplify: true` is passed in the options to `txml.parse()` if you expect a flattened, object-like structure for easy property access. The raw parsed output is an array of node objects requiring traversal.","cause":"Attempting to access properties on a raw parsed DOM object when `simplify: true` was intended, or incorrect understanding of the simplified object structure.","error":"TypeError: Cannot read properties of undefined (reading 'book')"},{"fix":"For Node.js, ensure `transformStream` is explicitly imported: `import { transformStream } from 'txml';`. For browser builds that intend to use `transformStream`, verify you are not using the 'small build' import (`txml/txml` or `txml/dist/txml`) which omits Node.js stream components.","cause":"The `transformStream` utility was not explicitly imported, or it was excluded from the bundle when using a 'small build' import path in a browser environment.","error":"Error: transformStream is not defined / Cannot find name 'transformStream'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/TobiasNickel/tXml","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/txml","openapi_spec":null,"status_page":null,"smithery":null,"categories":["serialization","data"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-18","install_tag":null}}