gpt4 book ai didi

xpath - VBScript:具有多个命名空间的 XPath 查询

转载 作者:行者123 更新时间:2023-12-03 15:59:04 24 4
gpt4 key购买 nike

我应该使用什么 XPath 查询来获取 GetLogisticsOfferDateResult 节点?我附上了我正在使用的 vbscript。我怀疑问题与文档中的多个 namespace 有关。但是如何在 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 设置必须如下所示:

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

那么 XPath 查询必须是:

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

关于xpath - VBScript:具有多个命名空间的 XPath 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3289088/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com