我有一些 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 完成上述所有操作,或者我还需要使用正则表达式?一些例子会很棒。