js使用插件完成xml转json

插件:xml2json.min.js

插件文件下载(不能上传附件):https://download.csdn.net/download/zhu_zhu_xia/89513965

html代码:

html 复制代码
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />
    <title>xml</title>
    <style>
      html,
      body {
        margin: 0px;
        overflow: hidden;
        width: 100%;
        height: 100%;
      }
    </style>
    <script type='text/javascript' src="xml2json.min.js"></script>
  </head>

  <body>
    <button onclick="changeXmlToJson()">测试</button>
  </body>
  <script type="text/javascript">
    var xml1 = "<?xml version='1.0' encoding='UTF-8'?><person><firstName>John</firstName><lastName>Smith</lastName><age>25</age><address><streetAddress>21 2nd Street</streetAddress><city>New York</city><state>NY</state><postalCode>10021</postalCode></address><phoneNumber><type>home</type><number>212 555-1234</number></phoneNumber><phoneNumber><type>fax</type><number>646 555-4567</number></phoneNumber><gender><type>male</type></gender></person>";                               
     function changeXmlToJson() {
      var x2js = new X2JS();
      var pxg = x2js.xml_str2json(xml1);
      debugger
     }
  </script>
</html>
相关推荐
largecode10 小时前
企业名称能在来电显示吗?号码显示公司名服务打通多终端展示
android·xml·ios·iphone·xcode·webview·phonegap
会编程的土豆12 小时前
Gin 中 `c.BindJSON` 与 `c.JSON` 详细讲解
c语言·json·gin
ID_180079054731 天前
企业级实战:淘宝商品详情 API简要说明,json数据返回参考
json
学习3人组1 天前
业务主表+JSON自定义字段
java·spring boot·json
Car122 天前
在vscode中添加一个tasks.json实现 rt thread的scons编译功能
vscode·json·build·scons
学习3人组2 天前
基于 主表 + JSON 自定义字段的条件查询
json
XMYX-02 天前
28 - Go JSON 数据操作
开发语言·golang·json
只可远观2 天前
Android XML命令式和Jetpack Compose声明式UI
android·xml
Promise微笑2 天前
Geo专家于磊:Json-LD优化实战SOP与双核四驱体系
大数据·人工智能·重构·json
专注VB编程开发20年2 天前
json和python元组,列表,字典对比
开发语言·python·json·php