Registry / devops / js-xml

js-xml

JSON →
library2.0.0jsnpmunverified

A simple XML parser and formatter for JavaScript, currently at version 2.0.0 (work in progress). It ships TypeScript type definitions. Release cadence is unknown due to early stage. Key differentiators: minimal API for parsing and building XML, intended for both Node.js and browser. Alternative to xml2js but lighter with fewer dependencies.

npm install js-xml
INSTALL
IMPORT
SIG · JS-XML
J
js-xml
devopsjavascriptv2.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

parseXML
import { parseXML } from 'js-xml'
import parseXML from 'js-xml'
Named export, not default. ESM only.
formatXML
import { formatXML } from 'js-xml'
const { formatXML } = require('js-xml')
Package is ESM-only (type: module). CJS require will fail.
XMLBuilder
import { XMLBuilder } from 'js-xml'
const XMLBuilder = require('js-xml').XMLBuilder
Named export, not a default export.

Shows parsing an XML string into a JS object and building XML from an object using the library's two main exports.

import { parseXML, XMLBuilder } from 'js-xml'; // Parse XML string const xml = '<root><item>value</item></root>'; const parsed = parseXML(xml); console.log(parsed); // { root: { item: 'value' } } // Build XML const builder = new XMLBuilder({ root: { item: 'value' } }); const output = builder.toString(); console.log(output); // '<root><item>value</item></root>'
Debug
Known issues
breakingESM-only: requires Node.js >= 12.22, and import syntax is mandatory.
fix
Switch from require() to import statements. Set 'type': 'module' in package.json or use .mjs extension.
affects: >=2.0.0
deprecatedVersion 1.x used a default export; v2.0.0 switched to named exports only.
fix
Replace 'import jsxml from 'js-xml'' with 'import { parseXML, formatXML, XMLBuilder } from 'js-xml''.
affects: >=2.0.0
gotchaparseXML returns null for malformed XML instead of throwing. Check for null.
fix
Always check if parseXML result is null before accessing properties.
affects: *
Errors
Common errors & fixes
require() of ES Module not supported
js-xml is ESM-only; require() does not work.
fix
Use dynamic import() or convert your project to ESM.
Cannot find module 'js-xml'
Missing dependency or wrong import path.
fix
Run 'npm install js-xml@2' and ensure package.json has type:module.
Uncaught TypeError: parseXML is not a function
Using default import 'import parseXML from 'js-xml'' instead of named import.
fix
Use 'import { parseXML } from 'js-xml''.
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
packagejs-xml
js-xml — npm install js-xml · libregistry