ltx is a JavaScript library designed for efficient XML building, parsing, serialization, and manipulation. Currently stable at version 3.1.2, it sees regular maintenance releases primarily focused on dependency updates and minor improvements, with a major version (v3.0.0) introducing significant breaking changes. A key differentiator of ltx is its performance-oriented design, offering its own fast default parser while also supporting integration with multiple third-party parsers like sax-js and saxes for more advanced XML features or specific use cases. It provides a succinct API for in-memory XML object manipulation, supports JSX compatibility via `ltx.createElement`, and offers tagged template literal support for convenient XML string creation. The library targets modern JavaScript environments and Node.js versions 12.4.0 and above. Its modular design allows users to swap out parser backends depending on performance requirements or specific XML feature needs, making it versatile for various XML processing tasks.
npm install ltxVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to programmatically build an XML element, serialize it to a string, and then parse an XML string to access its properties and children using the `ltx` library's `Element` and `Parser` classes.
Upgrade your Node.js environment to version 12.4.0 or newer.
Integrate `ltx` into your browser build pipeline using a compatible JavaScript bundler.
Refactor your code to implement the desired logic manually or use alternative methods available on `Element` for comparison and manipulation.
Update calls from `element.toJSON()` to `element.JSONify()`.
If advanced XML features are required, install a compatible third-party parser (e.g., `npm install saxes`) and register it with `ltx`'s parser system. Refer to the documentation for details on setting the active parser.
Manually create a new `Element` instance and copy properties/children, or refactor the logic to avoid direct cloning.
If working in an ESM context, use `import * as ltx from 'ltx';`. If strictly in CommonJS and encountering this, ensure your `node_modules` are correctly resolved, or consider if an older version of `ltx` is more compatible with your CJS-only setup, although v3.1.0 claims 'Fix dual ESM/CJS export'.
Replace `element.toJSON()` with `element.JSONify()`.