javascript - 你如何在 node.js 中获取和解析 xml?

标签 javascript xml node.js

如何使用 node.js 从网上获取 xml 并将其解析为 javascript 对象? 我一直在搜索 npm 寄存器,但只找到了如何解析 xml 字符串,而不是如何获取它。

最佳答案

要获取在线资源,您可以使用http.get()。数据可以加载到内存中,或者直接发送到 XML 解析器,因为有些支持解析流的特性。

var req = http.get(url, function(res) {
  // save the data
  var xml = '';
  res.on('data', function(chunk) {
    xml += chunk;
  });

  res.on('end', function() {
    // parse xml
  });

  // or you can pipe the data to a parser
  res.pipe(dest);
});

req.on('error', function(err) {
  // debug error
});

关于javascript - 你如何在 node.js 中获取和解析 xml?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19195207/

相关文章:

node.js - Express 下更复杂的静态文件服务

javascript - 在 sails.js 中仅生成后端

javascript - Chrome 扩展程序的 Flash 分析

javascript - 使用 pouchdb 进行多次复制的最佳实践?

java - 搜索 View java.lang.NullPointerException

xml - 如何得到2个属性相减的结果

javascript - 从 firebase 网络获取数据

javascript - Google Identity 工具包验证 IdToken 时出错(客户端 : Android, 后端 : Node. js)

php - 尝试在 PHP 中使用 x.509 证书对 SOAP 调用进行数字签名

node.js - 在生成器完成后调用 yeoman 生成器