xmlbuilder2
A fluent, chainable XML builder and parser for Node.js with XPath and object/JSON conversion support.
Repository Health
Technical Analysis
xmlbuilder2 is a full-featured XML toolkit for Node.js and browsers: it lets you build XML documents with a chainable, jQuery-like fluent API, parse existing XML into a traversable document object, convert between XML and plain JS objects or JSON, and query documents with a bundled XPath evaluator. It’s a rewrite of the older xmlbuilder package built on a spec-compliant DOM implementation rather than ad hoc string concatenation.
Because the document model implements the W3C DOM interfaces, xmlbuilder2 documents support standard DOM traversal and manipulation alongside its fluent builder shortcuts, and can serialize to string, DOM Document, or a plain JS object representation depending on what the consuming code needs.
What You Get
- A fluent, chainable API (
create().ele().txt().up()) for constructing XML documents - An XML parser that turns existing XML text into a traversable, spec-compliant DOM document
- Bidirectional conversion between XML and plain JS objects or JSON via
create(obj)/.toObject() - A bundled XPath evaluator for querying constructed or parsed documents
- Serialization to XML string, DOM
Document, or JS object with configurable formatting options - TypeScript type declarations and both CommonJS and ES module builds
Common Use Cases
- Generating XML payloads (SOAP requests, sitemaps, RSS/Atom feeds, config files) from a Node.js service
- Parsing third-party XML APIs or feeds and converting them into plain JS objects for downstream processing
- Querying an XML document with XPath expressions without pulling in a separate XPath library
- Round-tripping configuration or data files between an XML format and a JS object representation
Under The Hood
Architecture xmlbuilder2 is split into src/builder for the fluent construction API, src/readers for parsing XML text and JS objects into its internal document model, and src/writers for serializing that model back out to XML string, DOM Document, JS object, or JSON, with the whole document model implementing the W3C DOM Level 4 interfaces so builder output is a real, traversable DOM tree. Tech Stack It’s a dependency-light TypeScript library (its DOM implementation and XPath evaluator live in companion oozcitak/* packages) that ships CommonJS and ESM builds with full .d.ts type declarations, targeting both Node.js and browser environments. Code Quality The project maintains a substantial test suite across builder, reader, and writer behaviors and has stayed API-stable across major versions since its rewrite from the original xmlbuilder package, though release cadence has been infrequent recently. API Design The fluent builder API (.ele(), .att(), .txt(), .up()) reads close to the XML it produces, keeping the common case low-boilerplate, while power users can drop to the underlying DOM interfaces or writer/reader options for finer control over serialization formatting and namespace handling.
Used by 2 apps in this directory
Hoppscotch
Developer Tools
A lightweight, offline-capable API development ecosystem for testing HTTP, GraphQL, WebSocket, MQTT, and SSE endpoints across web, desktop, and CLI.
OneUptime
Monitoring
The complete open-source observability platform that replaces PagerDuty, Datadog, Sentry, and StatusPage with a single self-hostable system.