如何在node.js中将动态创建的JSON对象转换为XML?
我必须根据包含嵌套对象列表的available来动态创建JSON对象。
var Obj = {
root: {
Door_Keeper: {
ID: {
'#list': [{
Key: {
Name: "Door_Keeper_ID",
Value: DoorKeeper.dkId
}
}, {
Key: {
Key_Name: "ID",
Key_Value: DoorKeeper.id.Id
}
}]
},
Name: doorKeeper.dkName,
Description: doorKeeper.dkId,
Settings: dkSettings,
'#list':
//Here I have list of objects which will be added dynamically
}
}
};
我想从node.js
中的上述JSON对象生成XML字符串答案 0 :(得分:1)
使用npm库,js2xml,它就像是,
var Js2Xml = require("js2xml").Js2Xml;
var obj = ...... //as given by you in the question
var js2xml = new Js2Xml("root", obj);
js2xml.toString();