I am trying to use xml2js to parse apart xml from rest API return and then turn the modified JSON back into XML to send back. But I can't seem to get xml2js's default builder example from their GitHub to work. Any recommendation on what's wrong here or another node package to use to accomplish this?
我试图使用xml2js从rest API返回解析xml,然后将修改后的JSON重新转换为XML以发回。但我似乎无法从他们的GitHub中获取xml2js的默认构建器示例。有关此处的错误或其他节点包的任何建议可用于实现此目的吗?
var fs = require('fs'),
xml2js = require('xml2js');
var obj = { name: "Super", Surname: "Man", age: 23};
var builder = new xml2js.Builder();
var xml = builder.buildObject(obj);
The Error I am getting back is:
我得到的错误是:
var builder = new xml2js.Builder();
^
TypeError: undefined is not a function
at Object.<anonymous> (/path/test.js:6:15)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:901:3
2 个解决方案
#1
0
As I said on GitHub:
正如我在GitHub上所说:
This is because the XML Builder hasn't been published to npm yet. If you wish to use it, you should download the repo from GitHub and use it as such. (don't forget to run npm install
when doing so)
这是因为XML Builder尚未发布到npm。如果你想使用它,你应该从GitHub下载repo并使用它。 (这样做时不要忘记运行npm install)
#2
0
Agree, would be helpful if that was in the notes as wasted a little bit of time figuring out what was wrong and ended up here.
同意,如果在笔记中浪费一点点时间弄清楚什么是错的并且最终在这里会有帮助。
To install via NPM from master just use
要通过NPM从master安装只需使用
npm install https://github.com/Leonidas-from-XIV/node-xml2js/archive/master.tar.gz
npm install https://github.com/Leonidas-from-XIV/node-xml2js/archive/master.tar.gz
#1
0
As I said on GitHub:
正如我在GitHub上所说:
This is because the XML Builder hasn't been published to npm yet. If you wish to use it, you should download the repo from GitHub and use it as such. (don't forget to run npm install
when doing so)
这是因为XML Builder尚未发布到npm。如果你想使用它,你应该从GitHub下载repo并使用它。 (这样做时不要忘记运行npm install)
#2
0
Agree, would be helpful if that was in the notes as wasted a little bit of time figuring out what was wrong and ended up here.
同意,如果在笔记中浪费一点点时间弄清楚什么是错的并且最终在这里会有帮助。
To install via NPM from master just use
要通过NPM从master安装只需使用
npm install https://github.com/Leonidas-from-XIV/node-xml2js/archive/master.tar.gz
npm install https://github.com/Leonidas-from-XIV/node-xml2js/archive/master.tar.gz