Here we can see how to use the MSXML6.0 Library to Parse XML for your particular example. To use this example, you need to add a reference to MSXML6.0 in your VBA project.
I suggest you pay particular attention to the XPath variable '//value' and selectors such as .getNamedItem("code") --- there are many more of these that you would need to familiarize yourself with in order to become fluent in XML parsing. Fortunately a lot of this passes over into HTML parsing so it is a useful skill!
In this case, I have selected ALL value nodes. Iterating through them is as simple as doing a for loop based on the length of the array of nodes and using the .item(i) call.
Option Explicit
Sub test()
Dim strXml As String
strXml = "<values><value code=""1"">A</value><value code=""2"">B</value><value code=""3"">C</value></values>"
Dim objXML As MSXML2.DOMDocument60
Set objXML = New MSXML2.DOMDocument60
If Not objXML.LoadXML(strXml) Then 'strXML is the string with XML'
Err.Raise objXML.parseError.ErrorCode, , objXML.parseError.reason
End If
Dim entry_point As IXMLDOMNode
Set entry_point = objXML
Dim myNodes As IXMLDOMNodeList
Dim myElement As IXMLDOMElement
Dim myNode As IXMLDOMNode
Dim nNode As Integer
Set myNodes = entry_point.SelectNodes("//value")
If myNodes.Length > 0 Then
For nNode = 0 To myNodes.Length
Set myNode = myNodes(nNode) ' Get the first node.
If myNode Is Nothing Then
Else
Debug.Print myNode.Text
Debug.Print myNode.Attributes.getNamedItem("code").Text
End If
Next nNode
Else
Debug.Print "No nodes found."
End If
End Sub
Here is another case where I select all VALUES nodes and then iterate through the children of each VALUES node (assuming that all values nodes only have value children).
Option Explicit
Sub test()
Dim strXml As String
strXml = "<values><value code=""1"">A</value><value code=""2"">B</value><value code=""3"">C</value></values>"
Dim objXML As MSXML2.DOMDocument60
Set objXML = New MSXML2.DOMDocument60
If Not objXML.LoadXML(strXml) Then 'strXML is the string with XML'
Err.Raise objXML.parseError.ErrorCode, , objXML.parseError.reason
End If
Dim entry_point As IXMLDOMNode
Set entry_point = objXML
Dim myNodes As IXMLDOMNodeList
Dim myChildNodes As IXMLDOMNodeList
Dim myElement As IXMLDOMElement
Dim myNode As IXMLDOMNode
Dim myChildNode As IXMLDOMNode
Dim nNode As Integer
Dim nChildNode As Integer
Set myNodes = entry_point.SelectNodes("//values")
If myNodes.Length > 0 Then
For nNode = 0 To myNodes.Length - 1
Set myNode = myNodes(nNode)
If myNode Is Nothing Then
Else
Set myChildNodes = myNode.ChildNodes ' Get the children of the first node.
For nChildNode = 0 To myChildNodes.Length - 1
Debug.Print myChildNodes(nChildNode).Text
Debug.Print myChildNodes(nChildNode).Attributes.getNamedItem("code").Text
Next nChildNode
End If
Next nNode
Else
Debug.Print "No nodes found."
End If
End Sub