1、安装依赖包
npm install x2js
2、引入依赖,对 xml 进行解析
import x2js from "x2js"
const xx = new x2js()
const xmlStr = '<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><HisInterFaceResponse xmlns="http://tempuri.org/"><HisInterFaceResult><response><resultCode>0</resultCode><resultContent>调用接口成功!</resultContent><rowCount>3</rowCount><rows><row><IDENTITY_NAME>辽宁</IDENTITY_NAME></row><row><IDENTITY_NAME>河北</IDENTITY_NAME></row></rows></response></HisInterFaceResult></HisInterFaceResponse></soap:Body></soap:Envelope>'
// 嵌套多层,需要多次调用 xx.xml2js
const jsonObj = xx.xml2js(xmlStr)
const resultObj= xx.xml2js(jsonObj.Envelope.Body.HisInterFaceResponse.HisInterFaceResult)
console.log("解析结果", resultObj)