如果SOAP响应具有名称空间,则无法使用VBScript从SOAP响应中选择节点值

问题描述 投票:0回答:1

我试图使用VBScript获取XML中的一些节点值。如果我使用以下脚本的普通XML,那么它正确地获取预期的节点值。但是如果我使用具有命名空间的SOAP响应,那么下面的脚本会在突出显示的行中抛出以下错误:

对象要求:'node'

脚本:

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set xmlDoc = CreateObject("Microsoft.XMLDOM")

xmlDoc.Load editName
xmlDoc.SetProperty "SelectionNamespaces", "xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/' xmlns:sch='http://www.exchangerate.com/webservices/schemas' xmlns:xbe='http://www.exchangerate.com/rate'"

Set nNode = xmlDoc.SelectSingleNode(tag)

objSheet.Cells(i, Column).value = nNode.text  '<-- this fails

strResult = xmlDoc.Save(editName)   

我怎么解决这个问题?

示例响应XML:

enter image description here


输入:

tag="/SOAP-ENV:Envelope/SOAP-ENV:Body/sch:Request/sch:Response/xbe:ConversionRateResult"
xml soap vbscript xml-namespaces
1个回答
1
投票

我们必须使用相对Xpath来解析SOAP响应,并且通过使用相对Xpath作为tag =“// xbe:ConversionRateResult”来解决上述问题。

© www.soinside.com 2019 - 2024. All rights reserved.