Hi there,
I am using a web service for the first time and need some help extracting the values returned in the XML after the POST.
I have a loop which does this successfully once I specify the parent node. But within the XML returned there is a point in which another parent node with child items.
What I want the loop to do is extract the values at both levels, so that when it hits another parent with child nodes, it is able to loop through these too and extract the values of them also line by line as it has been doing at the top level. I can't figure out how to do this though. Code so far that extracts values for the first level:
here's an example of the XML that would be read:
I would want to get every value out of the nodes. They should be :
item: 101
2item: 102
item:10150467
item: 10150467
With the code above though I'm getting
item: 101
and then blanks
I am using a web service for the first time and need some help extracting the values returned in the XML after the POST.
I have a loop which does this successfully once I specify the parent node. But within the XML returned there is a point in which another parent node with child items.
What I want the loop to do is extract the values at both levels, so that when it hits another parent with child nodes, it is able to loop through these too and extract the values of them also line by line as it has been doing at the top level. I can't figure out how to do this though. Code so far that extracts values for the first level:
Code:
Dim Request As New MSXML2.XMLHTTP60
Dim Doc As New DOMDocument60
Dim xresult As MSXML2.IXMLDOMNode
Dim xentry As MSXML2.IXMLDOMNode
Dim xChild As MSXML2.IXMLDOMNode
Dim list As IXMLDOMNodeList
Dim r As Long
Dim sendXML As String
sendXML = "some send XML here"
With Request
.Open "POST", "[URL="http://vmrodshel107.oracleoutsourcing.com:45911/SLFDASUtilsWS/resources/DasUtils/getItems"]url here[/URL]", False, "username", "password"
.setRequestHeader "Content-Type", "text/xml"
.send sendXML
Doc.LoadXML .responseText
End With
Dim i As Integer
Set list = Doc.SelectNodes("//slf_item_ws_obj/item_ws_table/slf_item_ws_row")
Dim node As IXMLDOMNode, nd As IXMLDOMNode
Dim childNode As IXMLDOMNode
i = 4
For Each node In list
i = i + 1
MsgBox GetNodeValue(node, "item")
MsgBox GetNodeValue(node, "item_status")
MsgBox GetNodeValue(node, "slf_item_ws_row/item_level")
MsgBox GetNodeValue(node, "slf_item_ws_row/transaction_level")
MsgBox GetNodeValue(node, "slf_item_ws_row/concession_ind")
Next node
Set Doc = Nothing
End Sub
Function GetNodeValue(node As IXMLDOMNode, xp As String)
Dim n As IXMLDOMNode, nv
Set n = node.SelectSingleNode(xp)
If Not n Is Nothing Then nv = n.nodeTypedValue
GetNodeValue = nv
End Function
here's an example of the XML that would be read:
Code:
<slf_item_ws_obj>
<item_ws_table>
<slf_item_ws_row>
<error_message/>
<item>10150459</item>
<item_status>A</item_status>
<brand_name>A BRAND NAME</brand_name>
<child_items_ws_table>
<slf_child_items_ws_row>
<item>10150467</item>
<item_desc>RG:MULTI 2:1SIZE</item_desc>
<diff_1>MULTI2</diff_1>
<diff_1_desc>MULTI 2</diff_1_desc>
<diff_2>1SIZE</diff_2>
<diff_2_desc>1SIZE</diff_2_desc>
</slf_child_items_ws_row>
</child_items_ws_table>
</slf_item_ws_row>
I would want to get every value out of the nodes. They should be :
item: 101
2item: 102
item:10150467
item: 10150467
With the code above though I'm getting
item: 101
and then blanks