You can try xml2js. It's a simple XML to JavaScript object converter. It gets your XML converted to a JS object so that you can access its content with ease.

Here are some other options:

  1. libxmljs
  2. xml-stream
  3. xmldoc
  4. cheerio – implements a subset of core jQuery for XML (and HTML)

I have used xml2js and it has worked fine for me. The rest you might have to try out for yourself.

Answer from Mithun Satheesh on Stack Overflow
🌐
npm
npmjs.com › package › fast-xml-parser
fast-xml-parser - npm
6 days ago - const { XMLParser, XMLBuilder, XMLValidator} = require("fast-xml-parser"); const parser = new XMLParser(); let jObj = parser.parse(XMLdata); const builder = new XMLBuilder(); const xmlContent = builder.build(jObj);
      » npm install fast-xml-parser
    
Published   Mar 23, 2026
Version   5.5.9
Author   Amit Gupta
🌐
Geshan
geshan.com.np › blog › 2022 › 11 › nodejs-xml-parser
A beginner’s guide to parse and create XML with Node.js
November 27, 2022 - For this example, you will parse XML using the fast-xml-parser NPM library. Create an empty folder named nodejs-xml. Then run npm init -y to create a package.json file with all default values.
🌐
GitHub
github.com › rgrove › parse-xml
rgrove/parse-xml: A fast, safe, compliant XML parser for ...
A fast, safe, compliant XML parser for Node.js and browsers. - rgrove/parse-xml
Starred by 316 users
Forked by 16 users
Languages   JavaScript 56.3% | TypeScript 43.6% | HTML 0.1%
🌐
The Polyglot Developer
thepolyglotdeveloper.com › 2015 › 01 › parse-xml-response-nodejs
Parse An XML Response With Node.js
January 5, 2015 - Not all APIs return JSON so it is the application developers responsibility to handle the XML. Lucky for us there is a convenient package for Node.js called xml2js that will handle all the parsing for us.
🌐
LogRocket
blog.logrocket.com › home › reading and writing xml in node.js
Reading and writing XML in Node.js - LogRocket Blog
June 4, 2024 - Then add the express-xml-bodyparser middleware to the Express app. By default, the middleware will parse any incoming requests where if the request’s Content-Type header is set to text/xml.
Find elsewhere
🌐
Reddit
reddit.com › r/node › how to parse large xml file (2–3gb) in node.js within a few seconds?
r/node on Reddit: How to parse large XML file (2–3GB) in Node.js within a few seconds?
July 25, 2025 -

I have a large XML file (around 2–3 GB) and I want to parse it within a few seconds using Node.js. I tried packages like xml-flow and xml-stream, but they take 20–30 minutes to finish.

Is there any faster way to do this in Node.js or should I use a different language/tool?

context:

I'm building a job distribution system. During client onboarding, we ask clients to provide a feed URL (usually a .xml or .xml.gz file) containing millions of <job> nodes — sometimes the file is 2–3 GB or more.

I don't want to fully process or store the feed at this stage. Instead, we just need to:

  1. Count the number of <job> nodes

  2. Extract all unique field names used inside the <job> nodes

  3. Display this info in real-time to help map client fields to our internal DB structure

This should ideally happen in a few seconds, not minutes. But even with streaming parsers like xml-flow or sax, the analysis is taking 20–30 minutes.

I stream the file using gzip decompression (zlib) and process it as it downloads. so I'm not waiting for the full download. The actual slowdown is from traversing millions of nodes, especially when different job entries have different or optional fields.

🌐
johnnyreilly
johnnyreilly.com › home › blog › xml: read and write with node.js
XML: read and write with Node.js | johnnyreilly
November 22, 2022 - This post demonstrates reading and writing XML in Node.js using fast-xml-parser. We will use the Docusauruses XML sitemap as an example.
🌐
GeeksforGeeks
geeksforgeeks.org › node.js › convert-xml-data-into-json-using-node-js
Convert XML data into JSON using Node.js - GeeksforGeeks
July 23, 2025 - // Filename - app.js // import File System Module import fs from "fs"; // import xml2js Module import { parseString } from "xml2js"; //xml data var xmldata = '<?xml version=”1.0" encoding=”UTF-8"?>' + '<Student>' + '<PersonalInformation>' + '<FirstName>Sravan</FirstName>' + '<LastName>Kumar</LastName>' + '<Gender>Male</Gender>' + '</PersonalInformation>' + '<PersonalInformation>' + '<FirstName>Sudheer</FirstName>' + '<LastName>Bandlamudi</LastName>' + '<Gender>Male</Gender>' + '</PersonalInformation>' + '</Student>'; // parsing xml data parseString(xmldata, function (err, results) { // parsing to json let data = JSON.stringify(results) // display the json data console.log("results",data); });
🌐
NPM Compare
npm-compare.com › fast-xml-parser,xml-js,xml-parser,xml2js
fast-xml-parser vs xml2js vs xml-js vs xml-parser
All three usable packages convert XML strings into plain JavaScript objects—but they do it differently. Uses a recursive descent parser. By default, it preserves attribute names under a @_ prefix and text content under #text.
🌐
Apify
blog.apify.com › javascript-parse-xml
How to parse XML in JavaScript (step-by-step guide)
December 7, 2025 - Learn effective XML parsing in JavaScript using DOMParser, xml2js, and more. Master techniques for large files and writing XML data efficiently.
🌐
npm
npmjs.com › package › xml2js
xml2js - npm
Simple XML to JavaScript object converter. It supports bi-directional conversion. Uses sax-js and xmlbuilder-js. Note: If you're looking for a full DOM parser, you probably want JSDom.
      » npm install xml2js
    
Published   Jul 26, 2023
Version   0.6.2
Author   Marek Kubica
🌐
npm
npmjs.com › package › node-xml-parser
node-xml-parser - npm
April 6, 2025 - import { parseXML } from 'node-xml-parser' const XML = '<document><text>Hello, World</text><symbol data="!"/></document>' parseXML(XML) /* Features clean, easily readable output: XMLNode { tag: 'document', attributes: Map(0) {}, children: [ XMLNode { tag: 'text', attributes: Map(0) {}, children: [ XMLNode { tag: '@text', attributes: Map(1) { data -> 'Hello, World' }, children: [] } ] }, XMLNode { tag: 'symbol', attributes: Map(1) { data -> '!' }, children: [] } ] } */
      » npm install node-xml-parser
    
Published   Apr 06, 2025
Version   0.0.6
Author   Iannis de Zwart
🌐
Thesourcepedia
blog.thesourcepedia.org › xml-parsing-with-nodejs
XML parsing with NodeJS
August 9, 2022 - In simple understanding, the parser will not parse text in tag and either that text contains predefined entities or reserved character, it will not occurs any error. ... //Valid <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE list [ <!ELEMENT list (song)> <!ELEMENT song (singer-name)+> <!ELEMENT singer-name (#PCDATA)> ]> <list> <song> <singer-name> Ike - Tina Turner <![CDATA[ River Deep & Mountain High ]]> </singer-name> </song> </list>
🌐
W3Schools
w3schools.com › xml › xml_parser.asp
XML Parser
HTML CSS JAVASCRIPT SQL PYTHON ... PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST TOOLS · XML HOME XML Introduction XML How to use XML Tree XML Syntax XML Elements XML Attributes XML Namespaces XML Display XML HttpRequest XML Parser XML DOM XML ...
🌐
iProyal
iproyal.com › blog › javascript-parse-xml
How to Parse XML in JavaScript (With Examples)
October 14, 2025 - Use tools made for your environment: DOMParser for browsers, fast-xml-parser or xml2js for Node. Don’t bring in big libraries if your job is small. Handle errors with care and always check output after parsing.
🌐
GitHub
github.com › segmentio › xml-parser
GitHub - segmentio/xml-parser: simple non-compliant xml parser for nodejs
October 5, 2023 - var fs = require('fs'); var parse = require('xml-parser'); var xml = fs.readFileSync('examples/developerforce.xml', 'utf8'); var inspect = require('util').inspect; var obj = parse(xml); console.log(inspect(obj, { colors: true, depth: Infinity }));
Starred by 103 users
Forked by 36 users
Languages   JavaScript 98.4% | Makefile 1.6% | JavaScript 98.4% | Makefile 1.6%
🌐
GitHub
github.com › nodejs › node › issues › 2709
Native XML Parsing in Node.js? · Issue #2709 · nodejs/node
September 5, 2015 - I dunno is it a right place to ask this question.. Can we have native XML parsing like we have for json.. I just googled and found weather v8 has exposed any api's for XML parsing.. Just found this link https://code.google.com/p/v8-juice...
Author   sathishsoundharajan
🌐
UsefulAngle
usefulangle.com › post › 106 › nodejs-read-xml
Reading XML in Node.js
January 3, 2019 - const xml2js = require('xml2js'); const fs = require('fs'); const parser = new xml2js.Parser({ attrkey: "ATTR" }); // this example reads the file synchronously // you can read it asynchronously also let xml_string = fs.readFileSync("data.xml", "utf8"); parser.parseString(xml_string, function(error, result) { if(error === null) { console.log(result); } else { console.log(error); } });
🌐
Nfarina
nfarina.com › post › 34302964969 › a-lightweight-xml-document-class-for-nodejs-javascript
Nick Farina - A lightweight XML parser for NodeJS/JavaScript
A lightweight XML parser for NodeJS/JavaScript Check out xmldoc on Github or just npm install xmldoc. Ever need to parse a bit of XML in NodeJS? If so, you may be quite confused by your options. You...