代码之家  ›  专栏  ›  技术社区  ›  Shawn de Wet

VBScript:具有多个名称空间的XPath查询

  •  2
  • Shawn de Wet  · 技术社区  · 16 年前

    什么 XPath 我应该使用查询来访问 GetLogisticsOfferDateResult 节点?

    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
    
    2 回复  |  直到 16 年前
        1
  •  7
  •   RRUZ    15 年前

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

    Set requestedNode = responseDoc.selectSingleNode("//s:Envelope//s:Body//sc:GetLogisticsOfferDateResponse//sc:GetLogisticsOfferDateResult")
    
        2
  •  1
  •   Oded    16 年前

    http://schneider-electric.com/OrderEntryService )在你的代码里。

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

    您要么需要添加它,要么在属于它的元素前面加上前缀。