前端解析xml

1、安装依赖包

npm install x2js

2、引入依赖,对 xml 进行解析

import x2js from "x2js"
const xx = new x2js()
const xmlStr = '<response><resultCode>0</resultCode><resultContent>调用接口成功!</resultContent><rowCount>3</rowCount><rows><row><IDENTITY_NAME>辽宁</IDENTITY_NAME></row><row><IDENTITY_NAME>河北</IDENTITY_NAME></row></rows></response>'
// 嵌套多层,需要多次调用 xx.xml2js
const jsonObj = xx.xml2js(xmlStr)
const resultObj= xx.xml2js(jsonObj.Envelope.Body.HisInterFaceResponse.HisInterFaceResult)
console.log("解析结果",  resultObj)

你可能感兴趣的:(工作总结,前端,xml,javascript)