I have some XML that needs to be manipulated into a string to render some instructions. The text looks like this
<?xml version="1.0" encoding="UTF-8"?>
<instructions id="detection" version="1.0">
<instruction task="detection">
<phrase type="header">HAS THE CARD TURNED OVER?<nl/><nl/><nl/></phrase>
<phrase type="practice">you are now going to do a practice.<nl/><nl/></phrase>
<phrase type="real">You are now going to do a test.<nl/><nl/></phrase>
<phrase>As soon as the card turns face up:<nl/><nl/></phrase>
<phrase><ts/><ts/>Press YES.<nl/><nl/></phrase>
<phrase>Go as fast as you can and try not to make any mistakes.<nl/><nl/></phrase>
<phrase>If you press YES before a card turns face up, you will hear an error sound.</phrase>
</instruction>
</instructions>
Now, all I need to do is the following
- Replace all
<nl/>
with \n - Replace all
<ts/>
with \t - Conditionally select practice or real, probably by removing the other
- Remove all XML bits remaining to result in a string.
so lets say I want the practice version of this, I should end up with
HAS THE CARD TURNED OVER?\n\n\n
you are now going to do a practice.\n\n
As soon as the card turns face up:\n\n
\t\tPress YES.\n\n
Go as fast as you can and try not to make any mistakes.\n\n
If you press YES before a card turns face up, you will hear an error sound.
Now, I have the opportunity to change the structure of the XML if the current form isn't ideal for this, but what I'm not sure is if I can do all of the above with e4X or I need to also use regex's? Some examples would be great.
tags, work? – Amy Blankenship Jul 25 '12 at 02:50
instead of trying to replace with \n, then. I think you can just use tabs where you need tabs. At that point, you just need to call toString() on the XMLList containing your real or practice values. If you don't set condenseWhite on your TextArea, you may not even need the
tags, but could probably just format the text by putting carriage returns where you want them. – Amy Blankenship Jul 25 '12 at 03:16