Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Need Help with the Logic of my Program

  1. Aug 9, 2009 #1
    This is VBA Excel:

    Here is what I am trying to do. I have a MathML file saved as a .txt file. It is simialr to XML.

    From the XML file, we have a bunch of text that looks something like:


    I would ultimately like to have an array whose elements are the substrings:

    Array(1) = <mname>
    Array(2) = Salad
    Array(3) = </mname>

    So far what I have done is this

    Load the entire text file into one continuous string.

    I have then fed the string into an array called ElementaryArray such that each individual character of the giant string is an element of the array.

    Now I would like to sweep through the array, element by element, and determine the start and end positions of each substring.

    If it were simply a bunch of substrings like <mmm><mmm><rrr><rrr><ooo><ooo> it would be easy enough. I could simply find the first "<" and then find its corresponding closing ">" and then restart the loop at the ">" position.

    The problem is that not all of the strings start and end with the "<" & ">" characters.

    I need a way to determine if the character after a ">" is another "<" or not. And then if it is not another "<" I must mark that character's position and then find the next occurrence of "<" which will be the end position (+1) of the substring that does not start with a "<".

    Does that all make sense :smile: The tricky part is relating the two different cases via the counter such that I do not get any overlap.

    Any ideas?
  2. jcsd
  3. Aug 9, 2009 #2
    I am of course also open to suggestions of alternative approaches to this problem.
  4. Aug 9, 2009 #3
    Don't try to hack up a parser by yourself. Use an XML parser library (MathML is XML).
  5. Aug 9, 2009 #4
    Is that your suggestion? Because that was not what I had in mind when I said I was open to suggestions. :wink:

    Also, what does that mean?
  6. Aug 9, 2009 #5
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook