今天帮同事做一个数据对接,从返回的数据中提取想要的部分。返回的是一个WebService结果,由外圈的XML标记和中间的有效内容组成,现在要把有效内容取出来,VB6.0实现。
下面是返回的内容:
<?xml version='1.0' encoding='UTF-8'?> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Body> <ns:getAllQuickInfoResponse xmlns:ns="http://webservice.sp.action.org" xmlns:ax21="http://service.webservice.sp.action.org/xsd"> <ns:return> [...省略] </ns:return> </ns:getAllQuickInfoResponse> </soapenv:Body> </soapenv:Envelope>
要把中间的有效内容取出来。想到了正则表达式,在VB6中用法如下:
首先要添加正则表达式的引用:
菜单栏: “工程” - “引用” - “Microsoft VBScript Regular Expressions 5.5”
用法:
'获取有效内容 Dim str As String Dim re As RegExp Dim mh As Match Dim mhs As MatchCollection str = HttpClient.responseText Set re = New RegExp re.Pattern = "\[.*]" Set mhs = re.Execute(str) Set mh = mhs(0) MsgBox (mh.Value)
效果:
原文链接:https://www.f2er.com/vb/257218.html