Hi
I didn't follow your lead, but started down another path instead. I'll describe my thinking and you decide whether or not it is useful.
But first, a little correction. You say you can import the MathML code into a string array like this:
Array(1) = <mrow>
Array(2) = <mi>
Array(3) = x
Array(4) = <mi>
Maybe it's only a typo, but if not, then the importing code should be modified so that
Array(4) = </mi> . It would be so much easier to locate the corresponding closing part of a tag this way.
Now, about the algorithm. I would look for certain operators in the MathML code. For example, it seems
division is represented by
<mfrac>. The expression
a/b would look like
<mfrac>
<mi>
a
</mi>
<mi>
b
</mi>
</mfrac>
Within an
<mfrac> tag there should be 2 pairs of tags on the same level: one contains the divident, the other the divider. So, when
<mfrac> tag is found in the array, take the tags on the next level, and replace them by
(). In between them, a
/ operator should be placed in the resulting expression. Like this:
<mfrac>
(
a
)
/
(
b
)
</mfrac>
Then any pairs of parentheses that don't have at least one operator between them can be removed.
The same logic goes for raising to powers. I guess it will also work for multiplication, but your example doesn't show it. For clarification purpose, please tell me how the following expression would look like in MathML:
Actually, without this info my whole "algorithm" so far is based on hope only.
Jimmy