JavaScript XML libraries

Updated Nov 2026

JavaScript XML libraries parse XML documents into objects or DOM trees and write XML back out. A streaming parser emits an event for each tag rather than loading the whole document into memory. These libraries let apps read feeds, sitemaps, and SOAP responses from services that return XML.

Popularity

saxes has the most monthly downloads in this comparison, at 617.8M.

LibraryMonthly downloadsStarsLast releaseLicense
saxes
617.8M
86Nov 2021ISC
sax
503.6M
1.2KJul 2026BlueOak-1.0.0
fast-xml-parser
438.8M
3.1KNov 2026MIT
xmldom
334.7M
476Aug 2026MIT
xml2js
243.7M
5.0KJul 2023MIT
xmlbuilder2
65.0M
410Dec 2025MIT
xml-js
59.5M
1.3KFeb 2019MIT
libxmljs2
3.0M
0Jun 2025MIT
Downloads: npm, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

Features compared

LibraryIncremental XML inputXML generationXSD validation
saxesBuilt-inUnsupportedUnsupported
saxBuilt-inUnsupportedUnsupported
fast-xml-parserUnsupportedBuilt-inUnsupported
xmldomUnsupportedBuilt-inUnsupported
xml2jsUnsupportedBuilt-inUnsupported
xmlbuilder2UnsupportedBuilt-inUnsupported
xml-jsUnsupportedBuilt-inUnsupported
libxmljs2Built-inBuilt-inBuilt-in
Built-inNot supported

Libraries and code examples

Parses XML as a stream of events.

Downloads / mo
617.8M
Stars
86
Last release
6.0.0
License
ISC

Quickstart

From README.md
$ npm install saxes
const { SaxesParser } = require('saxes');

const parser = new SaxesParser({ xmlns: true });
parser.on('text', text => console.log(text));
parser.write('<root>Hello</root>').close();

Emits events while it parses an XML stream.

Downloads / mo
503.6M
Stars
1.2K
Last release
1.6.1
License
BlueOak-1.0.0

Quickstart

From README.md
$ npm install sax
const sax = require('sax');

const parser = sax.parser(true);
parser.ontext = text => console.log(text);
parser.write('<root>Hello</root>').close();

sax examples

From open-source projects on GitHub

fast-xml-parser

Parses XML into JavaScript objects and builds XML through a configurable JavaScript API.

Downloads / mo
438.8M
Stars
3.1K
Last release
5.12.1
License
MIT

Strengths

  • Controls which tags become arrays. Use isArray to give selected XML elements a consistent shape.
  • Preserves tag order when configured. Enable preserveOrder when XML content order matters.

Limitations

  • Attributes are ignored by default. Set ignoreAttributes:false when attributes are part of the data.
  • Syntax validation is opt-in. Pass true to parse or call XMLValidator explicitly.

Quickstart

From README.md
$ npm install fast-xml-parser
const { XMLParser } = require('fast-xml-parser');

const parser = new XMLParser();
const result = parser.parse('<root>text</root>');

fast-xml-parser examples

From open-source projects on GitHub
export const sortPomFile = (pomFile: string, { xmlParserOptions, xmlBuildOptions }: SortPomFileOptions = {}): string => {
  const parser = new XMLParser({ ...defaultXmlParserOptions, ...xmlParserOptions });
  const pomObject = parser.parse(pomFile);
  pomObject.project = sortPomProject(pomObject.project);

  const builder = new FastXmlBuilder({ ...defaultXmlBuildOptions, ...xmlBuildOptions });
  return formatPomFirstLevel(builder.build(pomObject));
};

Provides JavaScript XML DOM parsing, document-tree editing, and XML serialization.

Downloads / mo
334.7M
Stars
476
Last release
0.9.12
License
MIT

Strengths

  • Edits DOM nodes directly. Create elements, update attributes, and change the document tree.
  • Serializes DOM trees to XML. Convert edited documents back to strings with XMLSerializer.

Limitations

  • XPath integration uses another package. Pair xpath, a path-query library, with the parsed DOM.
  • Browser DOM compatibility is partial. Check required browser APIs before sharing DOM-dependent code with Node.

Quickstart

From readme.md
$ npm install @xmldom/xmldom
const { DOMParser, MIME_TYPE } = require('@xmldom/xmldom');

const document = new DOMParser().parseFromString('<root/>', MIME_TYPE.XML_TEXT);

xmldom examples

From open-source projects on GitHub

Maps XML to JavaScript objects and builds XML from object data.

Downloads / mo
243.7M
Stars
5.0K
Last release
0.6.2
License
MIT

Strengths

  • Offers promise-based parsing. Use parseStringPromise in asynchronous XML loading workflows.
  • Builds attributes and text together. Use the object’s attribute and text keys when rebuilding XML.

Limitations

  • Round trips depend on settings. Keep defaults when exact object-to-XML round trips matter.
  • Parser reuse needs a reset. Create one parser per file or reset it between documents.

Quickstart

From README.md
$ npm install xml2js
import xml2js from 'xml2js';

const result = await xml2js.parseStringPromise('<root>text</root>');

xml2js examples

From open-source projects on GitHub

Builds XML documents in Node.js.

Downloads / mo
65.0M
Stars
410
Last release
4.0.3
License
MIT

Quickstart

From BuilderFunctions.d.ts
$ npm install xmlbuilder2
const { create } = require('xmlbuilder2');

const document = create().ele('root').txt('text');
const xml = document.end({ prettyPrint: true });

xmlbuilder2 examples

From open-source projects on GitHub

Converts between XML text and JavaScript objects or JSON.

Downloads / mo
59.5M
Stars
1.3K
Last release
1.6.11
License
MIT

Quickstart

From index.d.ts
$ npm install xml-js
const convert = require('xml-js');

const document = convert.xml2js('<root>text</root>');

xml-js examples

From open-source projects on GitHub

Provides libxml bindings for JavaScript.

Downloads / mo
3.0M
Stars
0
Last release
0.37.0
License
MIT

Quickstart

From index.d.ts
$ npm install libxmljs2
const libxml = require('libxmljs2');

const document = libxml.parseXml('<root/>');

libxmljs2 examples

From open-source projects on GitHub

FAQ

fast-xml-parser suits converting XML to JavaScript objects and back. xmldom suits code that needs a standard DOM to query and edit. saxes suits large documents that must stream.

fast-xml-parser parses XML into JavaScript objects and builds XML from objects. Its options control attributes, arrays, and value parsing.

xml2js maps XML to JavaScript objects and builds XML from object data. It wraps the sax parser in a callback and promise API.

Parse the XML into a JavaScript object with fast-xml-parser or xml-js, then pass the object to JSON.stringify.

A SAX parser reads XML as a stream and emits an event for each opening tag, text node, and closing tag. sax and saxes use this model for documents too large to hold in memory.

For coding agents

Found your XML library? Help your agent use it.

Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.

Run in your terminal

claude plugin install exa@claude-plugins-official