1 |
- {"ast":null,"code":"/**\r\n * Copyright 2019 Huawei Technologies Co.,Ltd.\r\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use\r\n * this file except in compliance with the License. You may obtain a copy of the\r\n * License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software distributed\r\n * under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR\r\n * CONDITIONS OF ANY KIND, either express or implied. See the License for the\r\n * specific language governing permissions and limitations under the License.\r\n *\r\n */\n\nfunction Xml2Json() {\n let json2Str = function (jsonObj) {\n let rejsn = JSON.stringify(jsonObj, undefined, 2).replace(/(\\\\t|\\\\r|\\\\n)/g, '').replace(/\"\",[\\n\\t\\r\\s]+\"\"[,]*/g, '').replace(/(\\n[\\t\\s\\r]*\\n)/g, '').replace(/[\\s\\t]{2,}\"\"[,]{0,1}/g, '').replace(/\"[\\s\\t]{1,}\"[,]{0,1}/g, '');\n return rejsn.indexOf('\"parsererror\": {') === -1 ? rejsn : 'Invalid XML format';\n };\n let setJsonObj = function (xmlDoc) {\n let jsonObj = {};\n if (xmlDoc.nodeType === 1) {\n if (xmlDoc.attributes.length > 0) {\n jsonObj['@attributes'] = {};\n for (let j = 0; j < xmlDoc.attributes.length; j++) {\n let attribute = xmlDoc.attributes.item(j);\n jsonObj['@attributes'][attribute.nodeName] = attribute.value;\n }\n }\n } else if (xmlDoc.nodeType === 3) {\n jsonObj = xmlDoc.nodeValue;\n }\n if (xmlDoc.hasChildNodes()) {\n for (let i = 0; i < xmlDoc.childNodes.length; i++) {\n let item = xmlDoc.childNodes.item(i);\n let nodeName = item.nodeName;\n if (jsonObj[nodeName] === undefined) {\n jsonObj[nodeName] = setJsonObj(item);\n } else {\n if (jsonObj[nodeName].push === undefined) {\n let old = jsonObj[nodeName];\n jsonObj[nodeName] = [];\n jsonObj[nodeName].push(old);\n }\n jsonObj[nodeName].push(setJsonObj(item));\n }\n }\n }\n return jsonObj;\n };\n let self = this;\n self.parseString = function (xml, rstr) {\n let xmlDoc;\n if (window.DOMParser) {\n xmlDoc = new window.DOMParser().parseFromString(xml, 'text/xml');\n } else {\n xmlDoc = new window.ActiveXObject('Microsoft.XMLDOM');\n xmlDoc.async = 'false';\n }\n let ret = json2Str(setJsonObj(xmlDoc));\n return rstr === undefined ? JSON.parse(ret) : ret;\n };\n}\nexport default new Xml2Json();","map":{"version":3,"names":["Xml2Json","json2Str","jsonObj","rejsn","JSON","stringify","undefined","replace","indexOf","setJsonObj","xmlDoc","nodeType","attributes","length","j","attribute","item","nodeName","value","nodeValue","hasChildNodes","i","childNodes","push","old","self","parseString","xml","rstr","window","DOMParser","parseFromString","ActiveXObject","async","ret","parse"],"sources":["F:/workspace/202226701027/huinongbao-app/node_modules/esdk-obs-browserjs/src/xml2js.js"],"sourcesContent":["/**\r\n * Copyright 2019 Huawei Technologies Co.,Ltd.\r\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use\r\n * this file except in compliance with the License. You may obtain a copy of the\r\n * License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software distributed\r\n * under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR\r\n * CONDITIONS OF ANY KIND, either express or implied. See the License for the\r\n * specific language governing permissions and limitations under the License.\r\n *\r\n */\r\n\r\nfunction Xml2Json() {\r\n\tlet json2Str = function(jsonObj) {\r\n\t\tlet rejsn = JSON.stringify(jsonObj, undefined, 2).replace(\r\n\t\t\t\t/(\\\\t|\\\\r|\\\\n)/g, '').replace(/\"\",[\\n\\t\\r\\s]+\"\"[,]*/g, '')\r\n\t\t\t\t.replace(/(\\n[\\t\\s\\r]*\\n)/g, '').replace(\r\n\t\t\t\t\t\t/[\\s\\t]{2,}\"\"[,]{0,1}/g, '').replace(\r\n\t\t\t\t\t\t/\"[\\s\\t]{1,}\"[,]{0,1}/g, '');\r\n\t\treturn (rejsn.indexOf('\"parsererror\": {') === -1) ? rejsn : 'Invalid XML format';\r\n\t};\r\n\t\r\n\t\r\n\tlet setJsonObj = function(xmlDoc) {\r\n\t\tlet jsonObj = {};\r\n\t\tif (xmlDoc.nodeType === 1) {\r\n\t\t\tif (xmlDoc.attributes.length > 0) {\r\n\t\t\t\tjsonObj['@attributes'] = {};\r\n\t\t\t\tfor (let j = 0; j < xmlDoc.attributes.length; j++) {\r\n\t\t\t\t\tlet attribute = xmlDoc.attributes.item(j);\r\n\t\t\t\t\tjsonObj['@attributes'][attribute.nodeName] = attribute.value;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t} else if (xmlDoc.nodeType === 3) {\r\n\t\t\tjsonObj = xmlDoc.nodeValue;\r\n\t\t}\r\n\t\tif (xmlDoc.hasChildNodes()) {\r\n\t\t\tfor (let i = 0; i < xmlDoc.childNodes.length; i++) {\r\n\t\t\t\tlet item = xmlDoc.childNodes.item(i);\r\n\t\t\t\tlet nodeName = item.nodeName;\r\n\t\t\t\tif (jsonObj[nodeName] === undefined) {\r\n\t\t\t\t\tjsonObj[nodeName] = setJsonObj(item);\r\n\t\t\t\t} else {\r\n\t\t\t\t\tif (jsonObj[nodeName].push === undefined) {\r\n\t\t\t\t\t\tlet old = jsonObj[nodeName];\r\n\t\t\t\t\t\tjsonObj[nodeName] = [];\r\n\t\t\t\t\t\tjsonObj[nodeName].push(old);\r\n\t\t\t\t\t}\r\n\t\t\t\t\tjsonObj[nodeName].push(setJsonObj(item));\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn jsonObj;\r\n\t};\r\n\t\r\n\tlet self = this;\r\n\tself.parseString = function(xml, rstr) {\r\n\t\tlet xmlDoc;\r\n\t\tif (window.DOMParser) {\r\n\t\t\txmlDoc = new window.DOMParser().parseFromString(xml, 'text/xml');\r\n\t\t} else {\r\n\t\t\txmlDoc = new window.ActiveXObject('Microsoft.XMLDOM');\r\n\t\t\txmlDoc.async = 'false';\r\n\t\t}\r\n\t\tlet ret = json2Str(setJsonObj(xmlDoc));\r\n\t\treturn (rstr === undefined) ? JSON.parse(ret) : ret;\r\n\t};\r\n}\r\n\r\nexport default new Xml2Json();\r\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,QAAQA,CAAA,EAAG;EACnB,IAAIC,QAAQ,GAAG,SAAAA,CAASC,OAAO,EAAE;IAChC,IAAIC,KAAK,GAAGC,IAAI,CAACC,SAAS,CAACH,OAAO,EAAEI,SAAS,EAAE,CAAC,CAAC,CAACC,OAAO,CACvD,gBAAgB,EAAE,EAAE,CAAC,CAACA,OAAO,CAAC,uBAAuB,EAAE,EAAE,CAAC,CACzDA,OAAO,CAAC,kBAAkB,EAAE,EAAE,CAAC,CAACA,OAAO,CACtC,uBAAuB,EAAE,EAAE,CAAC,CAACA,OAAO,CACpC,uBAAuB,EAAE,EAAE,CAAC;IAChC,OAAQJ,KAAK,CAACK,OAAO,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC,GAAIL,KAAK,GAAG,oBAAoB;EACjF,CAAC;EAGD,IAAIM,UAAU,GAAG,SAAAA,CAASC,MAAM,EAAE;IACjC,IAAIR,OAAO,GAAG,CAAC,CAAC;IAChB,IAAIQ,MAAM,CAACC,QAAQ,KAAK,CAAC,EAAE;MAC1B,IAAID,MAAM,CAACE,UAAU,CAACC,MAAM,GAAG,CAAC,EAAE;QACjCX,OAAO,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;QAC3B,KAAK,IAAIY,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGJ,MAAM,CAACE,UAAU,CAACC,MAAM,EAAEC,CAAC,EAAE,EAAE;UAClD,IAAIC,SAAS,GAAGL,MAAM,CAACE,UAAU,CAACI,IAAI,CAACF,CAAC,CAAC;UACzCZ,OAAO,CAAC,aAAa,CAAC,CAACa,SAAS,CAACE,QAAQ,CAAC,GAAGF,SAAS,CAACG,KAAK;QAC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