作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 SOAP 消息如下:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header xmlns:v1="http://us.com/InventoryService/v1/"/>
<soapenv:Body xmlns:v1="http://us.com/InventoryService/v1/">
<v1:InventoryServiceResponse>
<v1:InventoryInfo>
<v1:productIdVal>ToothPick</v1:productIdVal>
<v1:localQuantityVal>0</v1:localQuantityVal>
<v1:localPlusQuantityVal>44</v1:localPlusQuantityVal>
<v1:nationalQuantityVal>1475</v1:nationalQuantityVal>
<v1:customerInventoryVal>0</v1:customerInventoryVal>
<v1:customerInventoryDate/>
<v1:customerInventorySource/>
<v1:inventoryDate/>
<v1:inventorySource/>
</v1:InventoryInfo>
</v1:InventoryServiceResponse>
</soapenv:Body>
Set oXML = CreateObject("MSXML2.DOMDocument")
oXML.Async = False
oXML.Load(sResponse)
oXML.SetProperty "SelectionLanguage", "XPath"
oXML.SetProperty "SelectionNamespaces", "xmlns:soapenv="& chr(34) & _
"http://schemas.xmlsoap.org/soap/envelope/" & Chr(34) & _
" xmlns:v1=" & Chr(34) & "http://us.com/InventoryService/v1/" & Chr(34)
Dim path
path = "/soapenv:Envelope/soapenv:Body/v1:InventoryServiceResponse/v1:InventoryInfo/v1:localQuantityVal"
Set acct = oXML.SelectNodes(path)
For Each objNode In acct
print objNode.text
Next
最佳答案
首先,您的 xml 没有结束标记 Envelope
.这应该是 xml:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header xmlns:v1="http://us.com/InventoryService/v1/"/>
<soapenv:Body xmlns:v1="http://us.com/InventoryService/v1/">
<v1:InventoryServiceResponse>
<v1:InventoryInfo>
<v1:productIdVal>ToothPick</v1:productIdVal>
<v1:localQuantityVal>0</v1:localQuantityVal>
<v1:localPlusQuantityVal>44</v1:localPlusQuantityVal>
<v1:nationalQuantityVal>1475</v1:nationalQuantityVal>
<v1:customerInventoryVal>0</v1:customerInventoryVal>
<v1:customerInventoryDate/>
<v1:customerInventorySource/>
<v1:inventoryDate/>
<v1:inventorySource/>
</v1:InventoryInfo>
</v1:InventoryServiceResponse>
</soapenv:Body>
</soapenv:Envelope>
Dim objXML, strPath, strNS, strXpath
strPath = "J:\Documents\Work\PersonalWork\Misc Codes\09042018_SO\read.xml" '<------Change this path correctly
strNS = "xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:v1=""http://us.com/InventoryService/v1/"""
set objXML = createobject("MSXML2.DomDocument")
objXML.async = false
objXML.load strPath
if objXML.parseError = 0 then
objXML.setProperty "SelectionNamespaces",strNS
strXpath = "//v1:InventoryServiceResponse/v1:InventoryInfo/v1:productIdVal"
set objNode = objXML.selectSingleNode(strXpath)
msgbox objNode.tagName & "--" & objNode.text
else
Msgbox objXML.ParseError.Reason
end if
set objXML = Nothing
关于xml - SOAP 响应的命名空间不适用于 XPath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49724838/
我是一名优秀的程序员,十分优秀!