node-xml2js

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

Library
npm
v0.6.2
4,959 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
47 /100 Fair
Development Activity 8
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
100%
Other

Activepieces

AI Assistants · Automation · Mcp

24,756

Open-source AI automation platform that converts 280+ workflow integrations into MCP servers for LLMs, with no-code builders and TypeScript extensibility.

View details
92
Repo Health
85
Technical
64
Dependency
Built with
TypeScript 100%
Updated 4 days ago
TypeScript
95%
MIT

Actual

Invoicing Finance

29,186

Local-first personal finance with envelope budgeting, end-to-end encryption, and multi-device sync — no subscription required.

View details
93
Repo Health
85
Technical
73
Dependency
Built with
TypeScript 95%
Updated 4 days ago
TypeScript
70%
Other

Budibase

Low Code Platforms · No Code Platforms

28,324

Build AI agents, automations, and internal apps on a single open-source platform with full self-hosting control.

View details
91
Repo Health
81
Technical
63
Dependency
Built with
TypeScript 70%
Svelte 26%
Updated 1 weeks ago
Rust
67%
MIT

Bun

Developer Tools

96,068

An all-in-one JavaScript and TypeScript toolkit — one Rust-and-JavaScriptCore binary that replaces Node.js, npm, a bundler, and a test runner with faster equivalents.

View details
92
Repo Health
91
Technical
64
Dependency
Built with
Rust 67%
C++ 19%
TypeScript 10%
Updated 5 days ago
C++
53%
Other

Cocos Engine

Design Tools · Developer Tools · Game Development

9,832

Open-source, cross-platform 2D/3D game engine with Vulkan, Metal, and WebGL support for web, mobile, and instant gaming platforms

View details
89
Repo Health
79
Technical
70
Dependency
Built with
C++ 53%
TypeScript 34%
Updated 1 weeks ago
TypeScript
93%
AGPL 3.0

CourseLit

Blogging · Ecommerce

1,268

Open-source, self-hosted LMS for selling online courses, digital downloads, and building communities on your own branded website.

View details
77
Repo Health
74
Technical
68
Dependency
Built with
TypeScript 93%
Updated 5 days ago
TypeScript
75%
Apache 2.0

Fern

Developer Tools

3,787

Fern turns a single OpenAPI, AsyncAPI, or Protobuf definition into type-safe SDKs for nine languages and a hosted API documentation site, all from one CLI and one source of truth.

View details
90
Repo Health
86
Technical
66
Dependency
Built with
TypeScript 75%
Updated 4 days ago
TypeScript
73%
AGPL 3.0

Firecrawl

AI Development · Developer Tools

185,614

Turn any website into clean, LLM-ready data with a single API call — no proxy headaches, no scraping complexity.

View details
89
Repo Health
83
Technical
65
Dependency
Built with
TypeScript 73%
Python 13%
Updated 4 days ago
TypeScript
54%
Other

Focalboard

Collaboration · Productivity · Project Management

26,491

Self-hosted, open source project management with Kanban, table, gallery, and calendar views — a privacy-first alternative to Trello, Notion, and Asana.

View details
56
Repo Health
82
Technical
64
Dependency
Built with
TypeScript 54%
Go 40%
Updated 4 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