作者:原来那只是梦靥 | 来源:互联网 | 2023-05-17 23:39
Imusingxml2jstobuilda.xmlfrommyregisters.Foreachelement,ineedtosetthekeywithsam
I'm using xml2js to build a .xml from my registers. For each element, i need to set the key with same name, example: key: product with an attribute id
我正在使用xml2js从我的寄存器中构建.xml。对于每个元素,我需要设置名称相同的键,例如:key: product with a attribute id
The expected result:
预期的结果:
Grand Hotel New York
120.80
...
My code:
我的代码:
var products = [];
_.each(list, function(element) {
var obj = {
name: element.title,
price: element.price,
};
products.push(obj);
});
var builder = new xml2js.Builder({rootName: 'products'});
var xml = builder.buildObject(products);
fs.writeFile('pacotes.xml', xml, (err) => {
if (err) throw (err);
});
Output result:
输出结果:
<0>
Mountain Do
0
0>
I checked the documentation, but nothing yet. Thanks
我检查了文件,但是还没有。谢谢
1 个解决方案