xml2json

功能描述

XML和JSON互相转换,用例见 xml2json_demo.html

依赖的模块

libs/xml2json.js
libs/json2xml.js

快速使用

引入 libs/xml2json.js

xml转json

  1. var xmlObj = `
  2. <note>
  3. <to>Tove</to>
  4. <from>Jani</from>
  5. <heading>Reminder</heading>
  6. <body>Don't forget me this weekend!</body>
  7. </note>
  8. `;
  9. // 第二个参数可格式化返回的数据显示在页面/控制器
  10. console.log(xml2json(xmlObj, " "));

json转xml

引入 libs/json2xml.js

  1. var jsonObj = `
  2. {
  3. "note": {
  4. "to":"Tove",
  5. "from":"Jani",
  6. "heading":"Reminder",
  7. "body":"Don't forget me this weekend!"
  8. }
  9. }
  10. `;
  11. // 第二个参数可格式化返回的数据显示在页面/控制器
  12. console.log(json2xml(jsonObj, " "));