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.
npm install txmlVerified import paths — ran on the pinned version, not inferred.
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.
Update import statements to `import * as txml from 'txml';` (ESM/TypeScript) or `const txml = require('txml');` (CommonJS), then use `txml.parse(xmlString, options);`.Migrate stream processing logic to use `transformStream`. Refer to documentation for updated usage patterns, including `for await` loops.
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.
Pass `{ keepWhitespace: true }` to the `txml.parse()` options object if whitespace preservation is required.If strict HTML parsing behavior for `hr` and similar tags is required, review and adjust the `noChildNodes` option to customize self-closing element definitions.
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(...)`).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.
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.No dependency data recorded yet.