XML和JSON互相转换,用例见 xml2json_demo.html
libs/xml2json.js
libs/json2xml.js
引入 libs/xml2json.js
var xmlObj = `
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
`;
// 第二个参数可格式化返回的数据显示在页面/控制器
console.log(xml2json(xmlObj, " "));
引入 libs/json2xml.js
var jsonObj = `
{
"note": {
"to":"Tove",
"from":"Jani",
"heading":"Reminder",
"body":"Don't forget me this weekend!"
}
}
`;
// 第二个参数可格式化返回的数据显示在页面/控制器
console.log(json2xml(jsonObj, " "));