繁体   English   中英

如何在node.js中将动态创建的JSON对象转换为XML?

[英]How to convert dynamically created JSON object to XML in node.js?

如何在node.js中将动态创建的JSON对象转换为XML?

我必须根据包含嵌套对象列表的可用对象动态创建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字符串

使用npm库js2xml ,就像

var Js2Xml = require("js2xml").Js2Xml;
var obj = ...... //as given by you in the question
var js2xml = new Js2Xml("root", obj);
js2xml.toString();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM