我有一个像这样的 AIML 文件:
<xml>
<aiml>
<category>
<pattern>Question 1</pattern>
<that>Optional</that>
<template>Answer</template>
</category>
<category>
<pattern>Question 2</pattern>
<that>Optional</that>
<template><random><li>Answer 1</li><li>Answer 2</li></random></template>
</category>
<topic name="test">
<category>
<pattern>Question 1</pattern>
<that>Optional</that>
<template><random><li>Answer 1</li><li>Answer 2</li><li>Answer 3</li></random></template>
</category>
</topic>
</aiml>
我想将其转换为 CSV:
0,Question 1,*,Optional, Answer,test.aiml
0,Question 2,*,Optional, <random><li>Answer 1</li><li>Answer 2</li></random>,test.aiml
0,Question 1,test,*, <random><li>Answer 1</li><li>Answer 2</li><li>Answer 3</li></random>,test.aiml
但结果是:
0,Question 1,*,Optional, Answer,test.aiml
0,Question 2,*,Optional, Answer 1Answer 2,test.aiml
0,Question 1,test,*, Answer 1Answer 2Answer 3,test.aiml
我不知道为什么,但是 node.getTextContent() 删除了所有标签并仅返回其内容。toString 返回标签名称。而且我找不到将随机和 li 标签作为文本处理的方法。这就是我获取标签内容的方式:
eElement.getElementsByTagName("template").item(0).getTextContent();