As far as XML parsing is concerned, which is the best node module, that I can use for XML parsing?
2 Answers
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:
- libxmljs
- xml-stream
- xmldoc
- 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.

- 589
- 6
- 10

- 27,240
- 14
- 77
- 101
-
5libxmljs allows traversing the xml with commands like `.find()`, really useful. – Rafael Xavier Jun 27 '13 at 20:39
-
5`xml-stream` worked for me very well. It's especially convenient when receiving XML data from a remote server. – esengineer Oct 18 '13 at 11:03
-
2xml2js has worked very nicely for me – rainabba Jan 10 '14 at 17:07
-
xml-stream doesn't work well with windows. Use xml-flow! https://github.com/matthewmatician/xml-flow – matthewmatician Sep 09 '15 at 22:36
-
For what it's worth [xml-js](https://github.com/nashwaan/xml-js) is very nice too. It has methods for XML to JS and vice versa, as well as XML to JSON and vice versa. – fullStackChris Dec 02 '20 at 05:51
-
[jsdom](https://www.npmjs.com/package/jsdom) could possibly added to the list as well, even though it does more than just parse xml – Klesun Apr 05 '22 at 08:49
This answer concerns developers for Windows. You want to pick an XML parsing module that does NOT depend on node-expat. Node-expat requires node-gyp and node-gyp requires you to install Visual Studio on your machine. If your machine is a Windows Server, you definitely don't want to install Visual Studio on it.
So, which XML parsing module to pick?
Save yourself a lot of trouble and use either xml2js or xmldoc. They depend on sax.js which is a pure Javascript solution that doesn't require node-gyp.
Both libxmljs and xml-stream require node-gyp. Don't pick these unless you already have Visual Studio on your machine installed or you don't mind going down that road.
Update 2015-10-24: it seems somebody found a solution to use node-gyp on Windows without installing VS: https://github.com/nodejs/node-gyp/issues/629#issuecomment-138276692

- 10,619
- 13
- 64
- 89
-
node-gyp does not require VS or Windows "node-gyp is a cross-platform command-line tool written in Node.js for compiling native addon modules for Node.js, which takes away the pain of dealing with the various differences in build platforms" – rainabba Jan 10 '14 at 17:05
-
20@rainabba That's why I wrote: This answer concerns developers for Windows. On Windows VS is required. – Christiaan Westerbeek Jan 24 '14 at 11:22
-
11@rainabba I wish quoting the first sentence of the node-gyp git repo makes it all okay. You clearly have not been plagued with node-gyp issues on window. – shanks Apr 28 '14 at 07:07
-
1wish i read this before trying to use xml-stream, couple of hours lost on trying to get node-gyp to work – Nuno Furtado Aug 13 '14 at 21:58
-
1Well if you run on a Linux machine, node-gyp seems to work just fine. I use node-expat, and it compiles fine everytime. Gcc compiler is installed by default on each machine, and its much lighter than VS. Also, you should take the standard practice and compile your modules ahead of time, and then deploy your `node_modules` directory with your project. The binaries VS will produce will work just fine, assuming your dev computer and your server are the same architecture(x86_64 probably). – tsturzl Aug 18 '14 at 21:21
-
1To add to that node-expat is the fastest XML parser I've found for node. Also its a SAX parser, and it parses streams rather than requiring the whole document be loaded into memory. I think node-expat is the best. Don't be lazy, and make sure you're using proper deploy methods. Therefore you'll only have to compile it once. – tsturzl Aug 18 '14 at 21:23
-
4_If your machine is a Windows Server, you definitely don't want to install Visual Studio on it._ Can anyone explain this statement? – Num Lock May 17 '16 at 11:36
-
5Visual Studio is a fairly heavy weight development tool, you don't usually want to install (and license) development tools, on production servers. – ThomasRedstone Sep 22 '16 at 12:15
-
1I was having issues with gyp and tried simply using the sax parser to parse the XML as a stream without the need of gyp. I added the module to NPM under the name `no-gyp-xml-stream` here: https://www.npmjs.com/package/no-gyp-xml-stream – Søren Ullidtz Nov 18 '16 at 10:32
-
-
1https://github.com/nodejs/node-gyp#option-1 I believe you can you MS build tools on the server w/o a full VS install. – berezovskyi Jun 22 '18 at 11:36
-
1Neither xmljs nor xmldoc are maintained anymore, are there any maintained alternatives? – Mike76 Oct 20 '20 at 16:25