Node .getTextContent() removing child tags and concatenating its content

时间:2016-04-15 15:00:57

标签: java csv aiml

I have a AIML file just like this:

<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>

And I want to convert it into 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

But the result is:

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

I don't know why but node.getTextContent() removes all tags and return only its content. toString returns the tag name. And I can't find a method to process random and li tags as text. Thats how I get the tag content:

eElement.getElementsByTagName("template").item(0).getTextContent();

0 个答案:

没有答案
相关问题