いくつかの命令をレンダリングするために、文字列に操作する必要がある XML があります。本文はこんな感じ
<?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>
今、私がする必要があるのは次のことだけです
<nl/>
すべてを \n に置き換えます<ts/>
すべて\t に置き換えます- おそらく他のものを削除することにより、条件付きで練習または実際を選択します
- 残っているすべての XML ビットを削除して、文字列にします。
だから私はこれの練習版が欲しいとしましょう、私は最終的に
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.
現在の形式がこれに適していない場合、XML の構造を変更する機会がありますが、e4X で上記のすべてを実行できるかどうか、または正規表現も使用する必要があるかどうかはわかりません。いくつかの例は素晴らしいでしょう。