I've been searching SO (and the rest of the Internet) for the answer, but I can't seem to find a solution for selecting an XML node based on an attribute.
This is my XML below this is for placing productcategoryid from a REST service XML
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">0</int>
<lst name="params">
<str name="q">*:*</str>
<str name="indent">true</str>
<str name="wt">xml</str>
</lst>
</lst>
<result name="response" numFound="5429" start="0">
<doc>
<int name="idProductCategory">2</int>
<str name="categoryname">Live Animals</str>
<int name="categoryLevel">2</int>
<str name="bestOfferEnabled">false</str>
<str name="leafCategory">true</str>
<int name="parentCategoryId">1</int>
<long name="_version_">1535190804282212352</long>
</doc>
</result>
</response>
I need to get the element of idProductCategory, i.e. 2, through VBA code, but I can't make it from below code.
Sub getProductCategory(prodCatName As String)
Dim result1 As String
Dim result As String
Dim myURL As String
Dim winHttpReq As Object
Set winHttpReq = CreateObject("WinHttp.WinHttpRequest.5.1")
myURL = "http://localhost:8080/solr/category/select?q=" & prodCatName & "&wt=json"
MsgBox myURL
winHttpReq.Open "GET", myURL, False
winHttpReq.Send
MsgBox winHttpReq.responseText
Dim doc_XML As DOMDocument60
Set doc_XML = New DOMDocument60
result = winHttpReq.responseText
doc_XML.Load result
Set List = doc_XML.documentElement.childNodes
For Each sub_list In List
If sub_list.Attributes(0).Text = "response" Then
For Each Node In sub_list.childNodes(0).childNodes
If Node.Attributes(0).Text = "idProductCategory" Then
result1 = Node.nodeTypedValue
End If
Next Node
End If
Next sub_list
End Sub
So please help me, I'm struggling on this I need to get element value by attribute name from this above XML and place it in a particular cell in Excel.