自动包装自定义 XML 标签并对其进行编号 [英] Automatically wrap custom XML tags and numbering them
问题描述
我有一个需要格式化为 XML 的游戏的对话脚本,格式如下...
I have a dialogue script for a game that needs to be formatted in XML, with following format...
<line id='1'> .............. </line>
<line id='2'> .............. </line>
<line id='3'> .............. </line>
....
<line id='n'> .............. </line>
我现在给出的对话脚本是用普通格式编写的,我只需要用上面的 XML 标签包装每一行.
Dialogue script I've given right now is written in plain format, I only need to wrap each lines in XML tags above.
有没有办法让流程自动化?
Is there a way to automate the process?
推荐答案
您可以通过两个步骤来实现.首先,在文本文件的每一行的开头添加一个行号.然后,将每一行包装在您需要的
XML 标记中.
You can achieve this in two steps. First, add a line number to the start of each line of your text file. Then, wrap each line in the <line>
XML tags which you need.
要生成行号,您可以使用列编辑器模式.首先,通过此查找和替换在每行的开头插入一个空格:
To generate line numbers, you can use column editor mode. First, insert a space the start of each line via this find and replacement:
查找:
(.*)
替换:
$1 (single space followed by $1)
然后使用列编辑器模式在每一行的开头插入一个生成的行号.有关如何执行此操作的详细信息,请参阅此处.此时,您的数据应如下所示:
Then use column editor mode to insert a generated line number at the start of each line. See here for more information on how to do this. At this point, your data should look something like this:
1 Here is line one.
2 Here is line two.
3 Here is line three.
...
111 Here is line one hundred eleven.
现在您可以进行第二次查找和替换以将每一行包裹在
标记中:
Now you can do a second find and replacement to wrap each line in the <line>
tag:
查找:
([0-9]+)\s+(.*)
替换:
<line id='$1'>$2</line>
这篇关于自动包装自定义 XML 标签并对其进行编号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!