tags:

views:

30

answers:

2

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/""&gt;&lt;s:Body&gt;&lt;GetLogisticsOfferDateResponse xmlns=""http://schneider-electric.com/OrderEntryService""&gt;&lt;GetLogisticsOfferDateResult&gt;2010-07-20&lt;/GetLogisticsOfferDateResult&gt;&lt;/GetLogisticsOfferDateResponse&gt;&lt;/s:Body&gt;&lt;/s:Envelope&gt;"'

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
A: 

You have not defined the default namespace of the document (http://schneider-electric.com/OrderEntryService) in your code.

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

You will either need to add it, or prefix the elements that belong to it with it.

Oded
OK I've edited the following line in my VBScript to read:responseDoc.setProperty "SelectionNamespaces", "xmlns='http://schneider-electric.com/OrderEntryService/' xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'"yet the call to the following line does not return a node:Set requestedNode = responseDoc.selectSingleNode("//s:Envelope//s:Body//GetLogisticsOfferDateResponse//GetLogisticsOfferDateResult")
Shawn de Wet
+1  A: 

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/'"

Then the XPath query had to be:

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

Shawn de Wet