Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The best node module for XML parsing [closed]

As far as XML parsing is concerned, which is the best node module, that I can use for XML parsing?

like image 704
Manoj Avatar asked Oct 08 '22 09:10

Manoj


People also ask

What is node in XML parsing?

According to the XML DOM, everything in an XML document is a node: The entire document is a document node. Every XML element is an element node. The text in the XML elements are text nodes. Every attribute is an attribute node.

How does node js work with XML?

Node. js has no inbuilt library to read XML. The popular module xml2js can be used to read XML. The installed module exposes the Parser object, which is then used to read XML.

What are the two types of XML parser?

In PHP there are two major types of XML parsers: Tree-Based Parsers. Event-Based Parsers.


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:

  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.

like image 219
Mithun Satheesh Avatar answered Oct 23 '22 00:10

Mithun Satheesh


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

like image 151
Christiaan Westerbeek Avatar answered Oct 23 '22 01:10

Christiaan Westerbeek