Here you can find your node:
Code:
Option Explicit
Const strNodeStartWith As String = "//"
Const strNoValueFound As String = "NoGivenNodeFoundPleaseCheck"
Sub HowToCall()
Dim varArrValue() As Variant
varArrValue = ReadXmlNode("C:\Test.xml", "Domain Name")
If varArrValue(LBound(varArrValue), UBound(varArrValue, 2)) <> strNoValueFound Then
MsgBox "Node found you can loop to get values.", vbInformation, "XML Node"
Else
MsgBox "Given node not found.", vbInformation, "XML Node"
End If
Erase varArrValue
End Sub
Function ReadXmlNode(ByVal XMLFilePath As String, ByVal NodeToSearch As String) As Variant
Dim xmlDoc As Object 'DOMDocument Object
Dim xmlNodes As Object 'IXMLDOMNodeList Object
Dim xmlNode As Object 'IXMLDOMNode Object
Dim lngCount As Long
Dim vararrValues() As Variant
Erase vararrValues
Set xmlDoc = CreateObject("MSXML2.DOMDocument")
xmlDoc.Load (XMLFilePath)
If Left(NodeToSearch, 2) <> strNodeStartWith Then NodeToSearch = strNodeStartWith & NodeToSearch
Set xmlNodes = xmlDoc.DocumentElement.SelectNodes(NodeToSearch)
If xmlNodes.Length > 0 Then
ReDim vararrValues(1 To xmlNodes.Length, 1 To 1)
lngCount = 0
For Each xmlNode In xmlNodes
lngCount = lngCount + 1
vararrValues(lngCount, 1) = xmlNode.Text
Next xmlNode
Else
ReDim vararrValues(1 To 1, 1 To 1)
vararrValues(1, 1) = strNoValueFound
End If
ReadXmlNode = vararrValues
xmlDoc.abort
Set xmlDoc = Nothing
Set xmlNodes = Nothing
Set xmlNode = Nothing
lngCount = Empty
Erase vararrValues
End Function
Bookmarks