<address id="ttjl9"></address>

      <noframes id="ttjl9"><address id="ttjl9"><nobr id="ttjl9"></nobr></address>
      <form id="ttjl9"></form>
        <em id="ttjl9"><span id="ttjl9"></span></em>
        <address id="ttjl9"></address>

          <noframes id="ttjl9"><form id="ttjl9"></form>

          JS實現xml與json互轉且基本保持原樣

          2019-11-8    seo達人



          如果非要代碼實現的話,github上一個不錯的js庫(X2JS):https://github.com/abdolence/x2js

          自己寫了demo測試了一下:



          <!DOCTYPE html>

          <html>

          <head>

          <meta charset="utf-8">

          <title></title>

          </head>

          <body>

          </body>

          <script src="js/xml2json.js" type="text/javascript" charset="utf-8"></script>

          <script type="text/javascript">

          var xmlText =

          '<mxGraphModel><root><mxCell id="0"/><mxCell id="1" parent="0"/><mxCell id="2" value="" style="ellipse;whiteSpace=wrap;html=1;" vertex="1" parent="1"><mxGeometry x="220" y="90" width="120" height="80" as="geometry"/></mxCell><mxCell id="3" value="" style="ellipse;whiteSpace=wrap;html=1;aspect=fixed;" vertex="1" parent="1"><mxGeometry x="410" y="110" width="80" height="80" as="geometry"/></mxCell></root></mxGraphModel>';

          console.log("原始數據xml:"+xmlText);

          var x2js = new X2JS();

          var jsonObj = x2js.xml_str2json( xmlText );

          console.log(jsonObj);

          var xmlAsStr = x2js.json2xml_str( jsonObj );

          console.log(xmlAsStr);

          </script>

          </html>

          效果如下:







          基本能還原,只是""變成了'',這個應該問題不大的。






          日歷

          鏈接

          個人資料

          藍藍設計的小編 http://www.syprn.cn

          存檔

          亚洲va欧美va天堂v国产综合