Really, I just can't believe that I constantly get the "Can't assign to array" error message...
I can read an XML file easily and assign the node values to a collection but the same is not true for an array. I don't know why, I guess I need to read more about Collection vs Array differences but anyway...
I finally came up with a 'dirty' alternative solution using an intermediary variant variable (vID). The code below works OK but... is it somehow possible to do this more elegantly, e.g. without a variant variable (no collections please)?!
Thanks!
I can read an XML file easily and assign the node values to a collection but the same is not true for an array. I don't know why, I guess I need to read more about Collection vs Array differences but anyway...
I finally came up with a 'dirty' alternative solution using an intermediary variant variable (vID). The code below works OK but... is it somehow possible to do this more elegantly, e.g. without a variant variable (no collections please)?!
Rich (BB code):
Sub ParseXML(sFileName As String)
'Trying to assign XML node values to an array cuz I hate Collections... sometimes!
Dim xFile As MSXML2.DOMDocument
Dim xNode As MSXML2.IXMLDOMNode
Dim xNodes As MSXML2.IXMLDOMNodeList
Dim vID
Dim NumberOfNodes As Integer
Dim i As Integer
Dim aTemp() As String
Set xFile = New MSXML2.DOMDocument
xFile.async = False
xFile.Load (sFileName)
'Start reading XML nodes
If Not xFile.SelectNodes("//NamedNode") Is Nothing Then
Set xNodes = xFile.SelectNodes("//NamedNode")
NumberOfNodes = xNodes.Length
ReDim Preserve aTemp(NumberOfNodes - 1) 'Preparing array for the loop
'This loop is important:
'i) XML node values are assigned to an intermediary variant vID, then
'ii) values of vID are assigned to array aTemp()
For Each xNode In xNodes
vID = xNode.Attributes.getNamedItem("id").Text
aTemp(i) = vID
i = i + 1
Next
Else
Debug.Print "No such nodes..."
End If
Set xFile = Nothing
'Stop
End Sub
Thanks!