VBScript:具有多个命名空间的 XPath 查询 [英] VBScript: XPath Query with multiple namespaces

查看:34
本文介绍了VBScript:具有多个命名空间的 XPath 查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应该使用什么 XPath 查询来访问 GetLogisticsOfferDateResult 节点?我附上了我正在使用的 vbscript.我怀疑问题与文档中的多个命名空间有关.但是如何引用 XPath 中的第二个命名空间?

What XPath query should I use to get to the GetLogisticsOfferDateResult Node? I have attached the vbscript that I'm using. I suspect the problem has to do with the multiple namespaces in the document. But how do I reference the second namespace in the XPath?

Dim responseXML
responseXML = '"<s:Envelope xmlns:s=""http://schemas.xmlsoap.org/soap/envelope/""><s:Body><GetLogisticsOfferDateResponse xmlns=""http://schneider-electric.com/OrderEntryService""><GetLogisticsOfferDateResult>2010-07-20</GetLogisticsOfferDateResult></GetLogisticsOfferDateResponse></s:Body></s:Envelope>"'

Dim responseDoc
Set responseDoc = WScript.CreateObject("MSXML2.DOMDocument.6.0")
responseDoc.loadXML(responseXML)
responseDoc.setProperty "SelectionNamespaces", "xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'"
Dim requestedNode
'This node is not found
'Set requestedNode = responseDoc.selectSingleNode("//s:Envelope//s:Body//GetLogisticsOfferDateResponse//GetLogisticsOfferDateResult")

'This node is found
Set requestedNode = responseDoc.selectSingleNode("//s:Envelope//s:Body")
'This node is found
'Set requestedNode = responseDoc.selectSingleNode("//s:Envelope")

If requestedNode Is Nothing Then
    WScript.Echo "Node not found"
Else
    WScript.Echo requestedNode.text
End If

Set responseDoc = Nothing
Set LODateNode = Nothing

推荐答案

原来我的 selectionNamespaces 设置必须如下:

Turns out my setting of selectionNamespaces had to be as follows:

responseDoc.setProperty "SelectionNamespaces", "xmlns:sc='http://schneider-electric.com/OrderEntryService' xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'"

那么 XPath 查询必须是:

Then the XPath query had to be:

Set requestedNode = responseDoc.selectSingleNode("//s:Envelope//s:Body//sc:GetLogisticsOfferDateResponse//sc:GetLogisticsOfferDateResult")

这篇关于VBScript:具有多个命名空间的 XPath 查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆