I have an XML file and this XML file has namespaces declared
This worked for me (after some amount of head-scratching)
Sub Tester()
Const XML As String = "<?xml version='1.0'?>" & _
"<CrystalReport xmlns='urn:crystal-reports:schemas:report-detail' " & _
" xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' " & _
" xsi:schemaLocation='urn:crystal-reports:schemas:report-detail " & _
" http://www.businessobjects.com/products/xml/CR2008Schema.xsd'>" & _
" <Test>Testing</Test>" & _
"</CrystalReport>"
Dim xmlDom As New MSXML2.DOMDocument60
Dim nodeList As MSXML2.IXMLDOMNodeList
Dim iNode As MSXML2.IXMLDOMNode
With xmlDom
.async = False
.validateOnParse = True
.LoadXML XML
.setProperty "SelectionLanguage", "XPath"
'set the default namespace and give it a prefix (e.g.) "xx"
.setProperty "SelectionNamespaces", _
"xmlns:xx='urn:crystal-reports:schemas:report-detail'"
'use the same default prefix in your XPath
Set nodeList = .SelectNodes("//xx:Test")
End With
Debug.Print nodeList.Length
For Each iNode In nodeList
Debug.Print iNode.XML
Next iNode
End Sub