{"id":11257,"library":"ltx","title":"ltx: JavaScript XML Library","description":"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.","status":"active","version":"3.1.2","language":"javascript","source_language":"en","source_url":"https://github.com/xmppjs/ltx","tags":["javascript"],"install":[{"cmd":"npm install ltx","lang":"bash","label":"npm"},{"cmd":"yarn add ltx","lang":"bash","label":"yarn"},{"cmd":"pnpm add ltx","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Optional backend for XML parsing, explicitly listed as a supported parser.","package":"node-xml","optional":true},{"reason":"Optional backend for XML parsing, explicitly listed as a supported parser.","package":"libxmljs","optional":true},{"reason":"Optional backend for XML parsing, explicitly listed as a supported parser.","package":"node-expat","optional":true},{"reason":"Optional backend for XML parsing, explicitly listed as a supported parser.","package":"sax-js","optional":true},{"reason":"Optional backend for XML parsing, explicitly listed as a supported parser.","package":"saxes","optional":true}],"imports":[{"note":"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.","wrong":"import ltx from 'ltx';\n// or\nconst ltx = require('ltx');","symbol":"ltx","correct":"import * as ltx from 'ltx';"},{"note":"The `Element` class is a core component for XML node representation. Since v3.0.0, `Element` is exported as a named class.","wrong":"const Element = require('ltx').Element;","symbol":"Element","correct":"import { Element } from 'ltx';"},{"note":"The base `Parser` class, or specific parser implementations, are named exports. Since v3.0.0, parser backends are exposed as classes.","wrong":"const Parser = require('ltx').Parser;","symbol":"Parser","correct":"import { Parser } from 'ltx';"}],"quickstart":{"code":"import { Element, Parser } from 'ltx';\n\n// 1. Build an XML element\nconst book = new Element('book', { id: 'bk101' })\n  .c('author').t('Gambardella, Matthew').up()\n  .c('title').t('XML Developer\\'s Guide').up()\n  .c('genre').t('Computer').up();\n\nconsole.log('Built XML:\\n', book.toString());\n\n// 2. Parse an XML string\nconst xmlString = `<catalog>\n  <book id=\"bk102\">\n    <author>Ralls, Kim</author>\n    <title>Midnight Rain</title>\n    <price>4.95</price>\n  </book>\n</catalog>`;\n\nconst parser = new Parser();\nlet parsedCatalog;\n\nparser.on('tree', (tree) => {\n  parsedCatalog = tree;\n});\n\nparser.parse(xmlString);\n\nconsole.log('\\nParsed XML Author:', parsedCatalog.getChild('book').getChild('author').getText());\nconsole.log('Parsed XML Book ID:', parsedCatalog.getChild('book').attrs.id);\n","lang":"typescript","description":"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."},"warnings":[{"fix":"Upgrade your Node.js environment to version 12.4.0 or newer.","message":"Version 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.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Integrate `ltx` into your browser build pipeline using a compatible JavaScript bundler.","message":"As 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.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Refactor your code to implement the desired logic manually or use alternative methods available on `Element` for comparison and manipulation.","message":"Several 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`.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Update calls from `element.toJSON()` to `element.JSONify()`.","message":"The `toJSON` method on `Element` was removed in v3.0.0 and replaced with `JSONify`. Calls to `toJSON` will fail.","severity":"breaking","affected_versions":">=3.0.0"},{"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.","message":"While `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`).","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Manually create a new `Element` instance and copy properties/children, or refactor the logic to avoid direct cloning.","cause":"Attempting to use the `clone` method on an `Element` instance after `ltx` v3.0.0, where this method was removed.","error":"TypeError: element.clone is not a function"},{"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'.","cause":"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.","error":"Error: require() of ES Module C:\\path\\to\\node_modules\\ltx\\lib\\index.js from C:\\your\\app.js not supported."},{"fix":"Replace `element.toJSON()` with `element.JSONify()`.","cause":"Calling the `toJSON` method on an `Element` instance after `ltx` v3.0.0, where it was renamed.","error":"TypeError: element.toJSON is not a function"}],"ecosystem":"npm"}