代码像这样:
var xml2js = require('xml2js');
var json = {
name : '张三',
sex : '难'
}
var builder = new xml2js.Builder(); // JSON->xml
var xml = builder.buildObject(json);
console.log('data:',xml);
输出的结果为:
<root>
<name>张三</name>
<sex>难</sex>
</root>
求怎么修改为
<xml>
<name>张三</name>
<sex>难</sex>
</xml>
var xml2js = require('xml2js');
var xml = {
name : '张三',
sex : '难'
}
var builder = new xml2js.Builder({headless:true}); // JSON->xml
var xml = builder.buildObject({xml:xml});
console.log('data:',xml);
详情请看xml2js的说明文档