自定义函数 JSAFILTERXML 从XML内容返回数组、位置、值。

function JSAFILTERXML(xml,returntypeof,searchvalue_index_qms,hms,index){

var arry = xml.split(/<[^<>]+>/g)

if(returntypeof == 1){return arry} //返回数组。

if(returntypeof == 2){return [...arry.entries()].filter(v=>v[1].includes(searchvalue_index_qms))} //返回所需值在数组中的位置,需参数searchvalue_index_qms。

if(returntypeof == 3){return arry[searchvalue_index_qms]} //返回所需值,需参数searchvalue_index_qms。

if(returntypeof == 4){ //返回包含所需值数组,需参数searchvalue_index_qms、hms。

var pphb = []

arry.forEach(v=>{

var reg = RegExp("(?<=" + searchvalue_index_qms + ")" + ".*?" + "(?=" + hms + ")","gs")

var ppsz = v.match(reg)

if(ppsz != null){pphb = pphb.concat(ppsz)}

})

return [...pphb.entries()]

}

if(returntypeof == 5){ //返回所需值,需参数searchvalue_index_qms、hms、index。

var pphb = []

arry.forEach(v=>{

var reg = RegExp("(?<=" + searchvalue_index_qms + ")" + ".*?" + "(?=" + hms + ")","gs")

var ppsz = v.match(reg)

if(ppsz != null){pphb = pphb.concat(ppsz)}

})

return pphb[index]

}

}

云南省
浏览 815
收藏
6
分享
6 +1
2
+1
全部评论 2
 
亂雲飛渡
亂雲飛渡

WPS寻令官

· 广东省
回复
 
答案
· 浙江省
回复