Hello all,
I'm looking to do a bit of string manipulation to identify groups of a string (the string formatted as XML), and randomize the order certain bits of the string given the right pattern. Here, let me show you an example of the full string:
<?xml version="1.0" encoding="utf-8"?>
<xml>
<description>
<text>Identify all body parts in French.</text>
<keyword>Challenge</keyword>
<keyword>Body parts</keyword>
<keyword>French</keyword>
</description>
<gamedata>
<word value="Garçon" answer="incorrect" />
<word value="Nez" answer="correct" />
<word value="Tête" answer="correct" />
</gamedata>
<gamedata>
<customdata label="theme" type="editbox">
<value>Le Corps</value>
</customdata>
</gamedata>
<language>French</language>
</xml>
I would like to take the nodes in the first <gamedata> branch, and randomize their order. For example, the proposed function would randomize the order of the 'garcon', 'nez', and 'tete' nodes. The randomizing part would be pretty simple once each one of the <word ... /> nodes are in an array. The trick is getting to that point and keeping the function flexible to work with XML structures that might have slightly different words.
Here is where I am looking to all of you for help. I would like to build a function that, given a string like the one above will be able to:
1 ~ Identify the chunk of the string in the first <gamedata> branch
2 ~ Find the opening of the next tag (in this case "<word ") and use that to explode the <gamedata> branch into individual items in an array. The complicated bit about this one is that I would like to avoid relying on the text "word" to explode -- instead I would like to identify the first "<" followed by whatever word comes and the next space -- thus working with all sorts of different XML structures (in case one uses a tag "<vocab " and so on).
All input is welcome! Thanks for all your help!
-Ange52