fast-xml-parser

Pure-JS XML parser, builder, and validator with no C/C++ bindings and no callbacks

Library
npm
v5.11.2
3,138 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
81 /100 Excellent
Development Activity 84
Maintenance 72
Community 68
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
81 /100 Excellent
Architecture 84
Code Quality 82
Innovation 80
Learning Curve 78

fast-xml-parser converts XML to JS objects and back without relying on native (C/C++) bindings or callback-based APIs, making it drop-in usable in Node.js, browsers, and bundler-based frontend builds alike. It exposes three focused classes — XMLParser, XMLBuilder, and XMLValidator — that cover the whole round trip: syntactically validating XML, parsing it into plain JS objects (optionally preserving tag order), and building XML back out of JS objects.

The library is tuned for throughput on files up to roughly 100MB, and handles XML/HTML edge cases directly, including unpaired tags (like <br>), stop nodes (like <script> content that shouldn’t be parsed), CDATA, comments, processing-instruction tags, and XML/HTML entity decoding. It ships as CommonJS, ESM, and a browser bundle, and includes a small CLI (fxparser) for ad-hoc validation and conversion from the command line.

What You Get

  • XMLParser class that converts XML strings (or byte arrays) into plain JS objects, with an option to preserve original tag order via preserveOrder
  • XMLBuilder class that converts JS objects back into XML strings, the inverse of XMLParser
  • XMLValidator (via XMLValidator.validate()) for syntactic XML validation with line/column error reporting, independent of parsing
  • Fine-grained parsing options: attribute handling, number/boolean coercion, CDATA and comment capture, custom tag/attribute value processors, and namespace-prefix stripping
  • Support for unpaired tags (<br>), stop nodes (content like <script>/<style> left unparsed), and configurable entity decoding (XML, HTML, and custom entities)
  • A fxparser CLI binary for validating or converting XML files from the terminal without writing any code
  • Distribution as CommonJS, native ESM, and a minified browser bundle (loadable via CDN) from a single package

Common Use Cases

  • Parsing SOAP/XML API responses into JS objects inside a Node.js backend or serverless function
  • Converting RSS/Atom feeds or sitemap XML into structured data for a static site generator or crawler
  • Round-tripping configuration or legacy data formats (e.g. Maven POMs, Ant build files, RSS) between XML and JSON
  • Validating untrusted XML input for well-formedness before passing it further down a processing pipeline
  • Parsing HTML-shaped documents where unpaired tags and stop nodes need explicit handling, distinct from strict XML

Under The Hood

Architecture — The library separates its three responsibilities into independent, composable modules under src/: validator.js for syntactic checks, xmlparser/ for parsing, and xmlbuilder/ (which re-exports the sibling fast-xml-builder package for the build direction). xmlparser/XMLParser.js is a thin public-facing class that wires together OptionsBuilder.js (merges user options over defaultOptions), OrderedObjParser.js (the 869-line core tokenizer/parser that walks the XML string and produces an order-preserving intermediate tree of XmlNode instances), and node2json.js (which, unless preserveOrder is requested, flattens that ordered tree into the conventional nested-object shape consumers expect). DocTypeReader.js handles DOCTYPE/entity declarations as a separate concern feeding into the parser. This gives a clear pipeline: raw XML string → optional validation → ordered node tree → optional prettify/flatten step → final JS object.

Tech Stack — Pure JavaScript with zero C/C++ native dependencies, published as type: module with dual ESM (src/fxp.js) and CommonJS (lib/fxp.cjs, built via Webpack per webpack.cjs.config.js) entry points plus TypeScript type declarations (src/fxp.d.ts, lib/fxp.d.cts). Runtime dependencies are all small, single-purpose sibling packages under the same NaturalIntelligence/nodable umbrella — @nodable/entities (HTML/currency entity tables), fast-xml-builder (the actual build-direction implementation), is-unsafe (prototype-pollution guarding), path-expression-matcher (jPath-style stop-node/array matching), strnum (safe numeric coercion), and xml-naming (tag/attribute naming helpers) — keeping the core parser’s own dependency surface minimal. Tests run on Jasmine with c8 for coverage; ESLint and Prettier enforce style.

Code Quality — The test suite is substantial: 27 spec files under spec/ covering CDATA, comments, entities (including a dedicated entities_security_spec.js for XML-entity-expansion/XXE-style attack vectors), stop nodes, path expressions, array-mode output, and large-file (large_spec.js) handling, run through c8 coverage reporting. OptionsBuilder.js centralizes all ~30 configuration flags with documented defaults, and onDangerousProperty in util.js explicitly guards against prototype-pollution-prone key names (e.g. __proto__) — a sign of security-conscious design given the library sits on the untrusted-input boundary. Public methods carry JSDoc comments describing parameter types and behavior.

API Design — The three-class surface (XMLParser, XMLBuilder, XMLValidator) maps directly onto the library’s stated jobs, and a minimal example (new XMLParser().parse(xml)) works with zero configuration, with power-user behavior (order preservation, custom entities, stop nodes, tag/attribute processors) opted into via a single options object rather than proliferating parameters. addEntity() and getMetaDataSymbol() are the only other public methods beyond parse/build/validate, keeping the API surface small and memorable. Trade-off: because v6 restructures this into a differently-shaped flexible-xml-parser, most current documentation and issue history still targets the v4/v5 API surface documented here.

Used by 32 apps in this directory

TypeScript
97%
MIT

NewsNow

Bookmarks Archiving

22,143

Self-hostable news aggregator with an elegant column layout, GitHub OAuth, adaptive scraping intervals, and seamless Cloudflare D1 or SQLite persistence.

View details
75
Repo Health
74
Technical
70
Dependency
Built with
TypeScript 97%
Updated 2 weeks ago
TypeScript
26%
AGPL 3.0

Omnivore

Bookmarks Archiving · Knowledge Management · Note Taking

16,356

Self-hosted read-it-later platform with highlights, newsletters, PDFs, and seamless Obsidian and Logseq integration.

View details
90
Repo Health
74
Technical
65
Dependency
Built with
TypeScript 26%
JavaScript 24%
HTML 20%
Updated 6 days 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 5 days ago
TypeScript
94%
MIT

open-seo

Developer Tools · Marketing

24,707

Pay-as-you-go open source SEO platform with MCP integration — keyword research, rank tracking, backlinks, site audits, and AI brand visibility in one self-hosted tool.

View details
83
Repo Health
79
Technical
74
Dependency
Built with
TypeScript 94%
Updated 6 days ago
TypeScript
85%
MIT

openwork

AI Assistants · Automation

24,237

OpenWork is a free, open-source desktop app for running AI agent workflows on your own files with 50+ LLMs, extensible skills, and MCP server support — the open-source alternative to Claude Cowork and Codex.

View details
87
Repo Health
89
Technical
67
Dependency
Built with
TypeScript 85%
Updated 5 days ago
TypeScript
94%
AGPL 3.0

Papra

Bookmarks Archiving

5,587

Self-hosted document archiving with email ingestion, OCR full-text search, and pluggable storage — store once, find anything.

View details
86
Repo Health
82
Technical
69
Dependency
Built with
TypeScript 94%
Updated 6 days ago
TypeScript
91%
AGPL 3.0

PeerTube

Social Media

15,362

A federated, ActivityPub-based video hosting platform built by Framasoft — self-hostable instances interconnect into a network with no vendor lock-in, P2P-assisted streaming, and no ads.

View details
96
Repo Health
75
Technical
66
Dependency
Built with
TypeScript 91%
Updated 1 weeks ago
TypeScript
81%
AGPL 3.0

Postiz

Automation · Social Media

37,683

The agentic social media scheduler — AI-powered content creation, 33-platform posting, and team workflows, all self-hosted.

View details
92
Repo Health
70
Technical
63
Dependency
Built with
TypeScript 81%
JavaScript 11%
Updated 6 days ago
TypeScript
98%
MIT

Promptfoo

AI Development

26,358

An open-source CLI and library for evaluating and red-teaming LLM applications — replace trial-and-error prompt engineering with systematic evals, vulnerability scanning, and CI/CD integration.

View details
90
Repo Health
73
Technical
67
Dependency
Built with
TypeScript 98%
Updated 5 days 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