node.js XML解析的最佳节点模块

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14890655/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 17:10:43  来源:igfitidea点击:

The best node module for XML parsing

node.jsxml-parsing

提问by Manoj

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

就 XML 解析而言,哪个是我可以用于 XML 解析的最佳节点模块?

回答by mithunsatheesh

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.

你可以试试xml2js。它是一个简单的 XML 到 JavaScript 对象转换器。它将您的 XML 转换为 JS 对象,以便您可以轻松访问其内容。

Here are some other options:

以下是一些其他选项:

  1. libxmljs
  2. xml-stream
  3. xmldoc
  4. cheerio– implements a subset of core jQuery for XML (and HTML)
  1. libxmljs
  2. xml流
  3. 文档
  4. Cheerio– 为 XML(和 HTML)实现核心 jQuery 的一个子集

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

我用过xml2js,对我来说效果很好。其余的你可能需要自己尝试。

回答by Christiaan Westerbeek

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 requiresyou 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.

此答案与 Windows 开发人员有关。您想选择一个不依赖于node-expat的 XML 解析模块。Node-expat 需要 node-gyp,而node-gyp 需要你在你的机器上安装 Visual Studio。如果你的机器是 Windows Server,你肯定不想在上面安装 Visual Studio。

So, which XML parsing module to pick?

那么,选择哪个 XML 解析模块?

Save yourself a lot of trouble and use either xml2jsor xmldoc. They depend on sax.jswhich is a pure Javascript solution that doesn't require node-gyp.

使用xml2jsxmldoc为自己省去很多麻烦。它们依赖于sax.js,这是一个不需要 node- gyp的纯 Javascript 解决方案。

Both libxmljsand xml-streamrequire 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.

无论libxmljsXML的流需要节点GYP。不要选择这些,除非你已经在你的机器上安装了 Visual Studio 或者你不介意走那条路。

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

2015-10-24 更新:似乎有人找到了在 Windows 上使用 node-gyp 而不安装 VS 的解决方案:https: //github.com/nodejs/node-gyp/issues/629#issuecomment-138276692