选择xmlbuilder
例子
var xml=builder.create('root')
.ele('xmlbuild')
.ele('repo',{"type":"git"},'git://github.com/oozcitak/xmlbuilder-js.git')
.end({pretty:true})
console.log(xml);
例子2
const superagent=require('superagent');
const cheerio=require('cheerio');
const reptileUrl="https://www.jianshu.com/";
const builder=require('xmlbuilder');
superagent
.get(reptileUrl)
.http2(true)
.end(function (err, res) {
if(err){
console.log(err);
}
let $=cheerio.load(res.text);
var root=builder.create('root');
root.com('测试');
$("#list-container .note-list li")
.each(function(i, elem) {
var item=root.ele('data')
item.ele('title',$(elem).find('.title').text())
item.ele('abstract',$(elem).find('.abstract').text())
})
var xml=root.end({pretty:true});
console.log(xml);
})
网友评论