Interpreting Math ML As Equations

My project is making Xojo read math ml code (which looks like xml) and output the corresponding equation.

I’m trying to do that by first identifying all the nodes of the math ml code and sending each node to a method (called SymAlph) that
will interpret the node names as symbols and store them into an array.

Here is some math ml code I want to read:

<math xmlns="http://www.w3.org/1998/Math/MathML">
<infinity/>
</math>

This code should just display the infinity symbol, ?.
I pass this math ml file as myFile to the method I’ve written below.
The following method should pass all the nodes of myFile to another method called SymAlph
that interprets the node names as symbols and stores them in an array.
The issue is I get the error OutOfBoundsException in the below code at the line “ElseIf stack(pointer) <> Nil Then”
Does anyone have a fix, or any suggestions or resources for me to whole issue of interpreting math ml as equations?

  Dim root As XmlNode
  Dim xmlDoc As New XmlDocument
  Dim stack() As Variant  //Needed to go through all the nodes of the math ml text
  Dim pointer As Integer
  pointer = 1
  xmlDoc.LoadXml(myFile)
  root = xmlDoc.DocumentElement
  While 1 = 1 //this loop should go through all the nodes of any math ml file
    If root <> Nil Then
      If root.ChildCount <> 0 Then 
        stack().Append(root.FirstChild)
      End
      SymCheck(root)   //store the symbols of the root
      If root.NextSibling <> Nil Then
        root = root.NextSibling
      ElseIf stack(pointer) <> Nil Then
        root = stack(pointer)
      ElseIf stack(pointer) = Nil Then
         Exit
      End
    ElseIf root = Nil Then
       Exit
    End
  Wend

pointer should probably start at 0