I’m using VBA to parse the soap xml with MSXML2 and XPath but while the XPath query works in various tools it doesn’t select anything in the selectNodes method. From what I’ve gathered from the numerous questions I’ve seen so far, I can use this ‘local-name’ syntax instead of specifying a namespace but nothing is ever selected. What am I doing wrong?
private const DQ = """"
Public Sub parseXML(sFileName As String)
Dim xmldoc As New MSXML2.DOMDocument60, I As IXMLDOMNodeList, x As IXMLDOMNode
With xmldoc
.loadXML sFileName
.SetProperty "SelectionLanguage", "XPath"
Set I = .selectNodes("//*[local-name()=" & DQ & "item" & DQ & "]")
If I.length > 0 Then
' do something useful
end if
End With
End Sub
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:Header></soap-env:Header>
<soap-env:Body>
<n0:ZBexQaasResponse xmlns:n0="urn:sap-com:document:sap:soap:functions:mc-style">
<Messages>
<item>
// some elements
</item>
</Messages>
<OutputTable>
<item>
// some elements
</item>
</OutputTable>
<TextElements></TextElements>
<XmlOutput></XmlOutput>
<XmlTxtelem></XmlTxtelem>
</n0:ZBexQaasResponse>
</soap-env:Body>
</soap-env:Envelope>
I don’t see why the code (with
loadinstead ofloadXMLand the necessaryasyncsetting, as already suggested in a comment) should not work and I can’t reproduce the problem, when I have the filetest2012011901.xmlasand the VBScript code
then both XPath expressions find the two
itemelements, as the output shows:So as far as I can tell my suggestions in the comment should fix your problem, you will need to elaborate if you still have problems.