Registry / serialization / ltx
library3.1.2jsnpmunverified

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 ltx
INSTALL
IMPORT
SIG · LTX
L
ltx
serializationjavascriptv3.1.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ltx
import * as ltx from 'ltx';
import ltx from 'ltx'; // or const ltx = require('ltx');
Since v3.0.0, the package primarily uses named exports and a module namespace object, making `import * as ltx` the recommended ESM approach. While CJS `require('ltx')` may work for some properties due to dual export, `import * as ltx` is explicit and robust.
Element
import { Element } from 'ltx';
const Element = require('ltx').Element;
The `Element` class is a core component for XML node representation. Since v3.0.0, `Element` is exported as a named class.
Parser
import { Parser } from 'ltx';
const Parser = require('ltx').Parser;
The base `Parser` class, or specific parser implementations, are named exports. Since v3.0.0, parser backends are exposed as classes.

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.

import { Element, Parser } from 'ltx'; // 1. Build an XML element const book = new Element('book', { id: 'bk101' }) .c('author').t('Gambardella, Matthew').up() .c('title').t('XML Developer\'s Guide').up() .c('genre').t('Computer').up(); console.log('Built XML:\n', book.toString()); // 2. Parse an XML string const xmlString = `<catalog> <book id="bk102"> <author>Ralls, Kim</author> <title>Midnight Rain</title> <price>4.95</price> </book> </catalog>`; const parser = new Parser(); let parsedCatalog; parser.on('tree', (tree) => { parsedCatalog = tree; }); parser.parse(xmlString); console.log('\nParsed XML Author:', parsedCatalog.getChild('book').getChild('author').getText()); console.log('Parsed XML Book ID:', parsedCatalog.getChild('book').attrs.id);
Debug
Known issues
breakingVersion 3.0.0 raised the minimum supported Node.js version to 12.4.0. Using older Node.js versions will result in runtime errors due to modern JavaScript syntax.
fix
Upgrade your Node.js environment to version 12.4.0 or newer.
affects: >=3.0.0
breakingAs of v3.0.0, `ltx` no longer exports a pre-bundled browser version. If you are targeting browser environments, you must use a module bundler like Webpack, Rollup, or Browserify to package `ltx` for client-side use.
fix
Integrate `ltx` into your browser build pipeline using a compatible JavaScript bundler.
affects: >=3.0.0
breakingSeveral methods on the `Element` class were removed in v3.0.0, including `clone`, `nameEquals`, `attrsEquals`, `childrenEquals`, and `equals`. Attempting to call these methods will result in a `TypeError`.
fix
Refactor your code to implement the desired logic manually or use alternative methods available on `Element` for comparison and manipulation.
affects: >=3.0.0
breakingThe `toJSON` method on `Element` was removed in v3.0.0 and replaced with `JSONify`. Calls to `toJSON` will fail.
fix
Update calls from `element.toJSON()` to `element.JSONify()`.
affects: >=3.0.0
gotchaWhile `ltx` provides its own fast parser, it is a simpler parser. For advanced XML features (e.g., DTDs, namespaces, validation) or different performance characteristics, you may need to explicitly register and use a third-party parser backend (e.g., `saxes`, `node-expat`).
fix
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.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: element.clone is not a function
Attempting to use the `clone` method on an `Element` instance after `ltx` v3.0.0, where this method was removed.
fix
Manually create a new `Element` instance and copy properties/children, or refactor the logic to avoid direct cloning.
Error: require() of ES Module C:\path\to\node_modules\ltx\lib\index.js from C:\your\app.js not supported.
Attempting to `require('ltx')` in a CommonJS module when `ltx` is primarily designed for ESM or has specific dual-package configurations that lead to this conflict in some environments.
fix
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'.
TypeError: element.toJSON is not a function
Calling the `toJSON` method on an `Element` instance after `ltx` v3.0.0, where it was renamed.
fix
Replace `element.toJSON()` with `element.JSONify()`.
Upgrade
Version history
3.1.2latest on npm
Audit
Dependencies
node-xmloptionalOptional backend for XML parsing, explicitly listed as a supported parser.
libxmljsoptionalOptional backend for XML parsing, explicitly listed as a supported parser.
node-expatoptionalOptional backend for XML parsing, explicitly listed as a supported parser.
sax-jsoptionalOptional backend for XML parsing, explicitly listed as a supported parser.
saxesoptionalOptional backend for XML parsing, explicitly listed as a supported parser.
Agent activity
2 hits · last 30 days
node
2
Resources
ltx — npm install ltx · libregistry