插件:xml2json.min.js
插件文件下载(不能上传附件):https://download.csdn.net/download/zhu_zhu_xia/89513965
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>