node-xml2js

XML-to-JavaScript-object parser and builder for Node.js

Library
npm
v0.6.2
4,960 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
46 /100 Fair
Development Activity 4
Maintenance 0
Community 80
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
66 /100 Good
Architecture 70
Code Quality 65
Innovation 55
Learning Curve 72

xml2js is a long-standing Node.js library that converts XML documents into plain JavaScript objects and can build XML back from JavaScript data structures. It wraps the SAX-based sax parser under a simpler, callback/promise-based API, exposing configuration options for common XML parsing headaches: attribute handling, namespace resolution, explicit-array normalization, whitespace trimming, and custom tag/attribute name processors.

Because raw XML-to-object conversion is ambiguous (should a repeated child element become an array? should attributes be nested under a special key or merged into the object?), xml2js’s large set of parser options exists specifically to let consumers pick the shape that matches how they intend to use the resulting object, rather than imposing one opinionated mapping. This flexibility, combined with its long track record and near-ubiquitous adoption in the Node ecosystem, is why it remains the default choice for parsing SOAP responses, RSS/Atom feeds, config files, and other legacy XML formats in JavaScript backends.

What You Get

  • A Parser class (and shorthand parseString/parseStringPromise functions) that converts an XML string into a plain JavaScript object
  • A Builder class that serializes a JavaScript object back into an XML string, using xmlbuilder internally
  • Configurable attribute handling (explicitArray, mergeAttrs, attrkey/charkey) to control the exact shape of the resulting object
  • XML namespace support, including stripping or preserving namespace prefixes during parsing
  • Custom tagNameProcessors/attrNameProcessors/valueProcessors hooks for transforming names and values during parsing

Common Use Cases

  • Parsing SOAP API responses into JavaScript objects for further processing
  • Reading legacy XML configuration files (e.g. web.config, Maven pom.xml-style files) in Node.js tooling
  • Converting RSS/Atom XML feeds into JSON-like structures for feed readers or aggregators
  • Round-tripping XML in migration or ETL scripts that need to modify a document and re-serialize it
  • Interfacing with older enterprise systems and APIs that only expose XML endpoints

Under The Hood

Architecture The library is a thin, well-organized wrapper around two lower-level packages: sax for the actual XML tokenizing/parsing and xmlbuilder for serialization. lib/parser.js (the largest file, ~395 lines) implements the Parser class, which drives a sax stream and, on each SAX event (open tag, text, close tag), incrementally builds up the target JavaScript object according to the active options; lib/builder.js mirrors this in reverse, walking a JS object and emitting an xmlbuilder document. lib/defaults.js centralizes the option presets for the two supported parsing “modes” (0.1 legacy defaults vs 0.2 current defaults), and lib/processors.js implements the built-in name/value processor functions (e.g. stripPrefix, parseNumbers) that users can opt into.

Tech Stack Source is written in CoffeeScript (src/) and compiled to the published CommonJS JavaScript (lib/) via a Cakefile build script; the only runtime dependencies are sax (XML tokenizing) and xmlbuilder (XML serialization) — both mature, minimal libraries.

Code Quality Tests are written in CoffeeScript (test/*.test.coffee) covering the parser, builder, BOM-handling, and processor functions, run via nyc/zap with Coveralls coverage reporting wired into CI. Since core logic is compiled from CoffeeScript rather than hand-written JS, contributors need CoffeeScript familiarity to modify lib/ directly (or must edit src/ and rebuild), which is an unusual but consistent pattern for a project this size and age.

API Design The primary entry points — parseString(xml, callback), parseStringPromise(xml), and new Builder().buildObject(obj) — are simple and immediately usable with zero configuration, while the large options object (explicitArray, mergeAttrs, explicitRoot, attrkey, etc.) is layered on top for cases needing precise control over the JS-object shape. This two-tier design (simple defaults, deep configurability) is why it has remained a stable dependency for over a decade despite XML parsing inherently requiring many edge-case decisions.

Used by 19 apps in this directory

TypeScript
93%
Apache 2.0

InsForge

Databases · Developer Tools

13,176

The all-in-one, open-source backend platform purpose-built for AI coding agents — giving your agent database, auth, storage, edge functions, a model gateway, and compute to ship full-stack apps end-to-end.

View details
86
Repo Health
81
Technical
72
Dependency
Built with
TypeScript 93%
Updated 6 days ago
TypeScript
77%
Other

Joplin

Note Taking

56,853

The privacy-first, open-source note-taking app with end-to-end encrypted sync, AI assistance, and a powerful plugin ecosystem across every platform.

View details
93
Repo Health
87
Technical
60
Dependency
Built with
TypeScript 77%
JavaScript 14%
Updated 1 weeks ago
TypeScript
98%
Other

Kibana

Analytics · Monitoring

21,338

Your open source window into the Elastic Stack — query, visualize, and act on data stored in Elasticsearch with real-time dashboards, AI-assisted search, and automated alerting.

View details
98
Repo Health
87
Technical
63
Dependency
Built with
TypeScript 98%
Updated 6 days ago
TypeScript
95%
MIT

melty

AI Code Assistants · Code Editors · Developer Tools

5,462

The AI code editor where every chat message is a git commit you can revert, branch, or squash

View details
35
Repo Health
75
Technical
67
Dependency
Built with
TypeScript 95%
Updated 1 years ago
TypeScript
92%
Other

n8n

Automation · No Code Platforms

208,437

Code when you need it, UI when you don't — the workflow automation platform built for technical teams who refuse to choose.

View details
95
Repo Health
87
Technical
62
Dependency
Built with
TypeScript 92%
Updated 1 weeks ago
TypeScript
96%
Apache 2.0

OneUptime

Monitoring

7,751

The complete open-source observability platform that replaces PagerDuty, Datadog, Sentry, and StatusPage with a single self-hostable system.

View details
91
Repo Health
81
Technical
65
Dependency
Built with
TypeScript 96%
Updated 6 days ago
JavaScript
64%
AGPL 3.0

overleaf

Collaboration · Productivity

18,266

Open-source, real-time collaborative LaTeX editor with sandboxed compilation and full TeXLive support for self-hosted academic and research teams.

View details
84
Repo Health
80
Technical
59
Dependency
Built with
JavaScript 64%
TypeScript 30%
Updated 1 months ago
TypeScript
97%
Other

Rocket.Chat

Team Chat

46,304

The secure, self-hosted team communications platform for organizations that cannot compromise on data sovereignty.

View details
96
Repo Health
79
Technical
63
Dependency
Built with
TypeScript 97%
Updated 6 days ago
TypeScript
95%
Apache 2.0

Void

AI Code Assistants · Automation · Code Editors

28,733

Open-source AI code editor with direct LLM integration and data privacy

View details
44
Repo Health
84
Technical
68
Dependency
Built with
TypeScript 95%
Updated 5 months ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers