I want to generate a xml file in the following format,
<emotionml version="1.0" xmlns="http://www.w3.org/2009/10/emotionml">
<emotion><category name="angry"/>
What was that all about?
</emotion>
</emotionml>
I created a method to get this output in java. But the I couldn't get the right output.
public Document printEmotionML(String sentence, String emotion) {
Document emotiondoc = null;
try {
DocumentBuilderFactory dbFactory =
DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder =
dbFactory.newDocumentBuilder();
emotiondoc = dBuilder.newDocument();
Element rootElement = emotiondoc.createElement("emotionml");
emotiondoc.appendChild(rootElement);
Element emotionEl = emotiondoc.createElement("emotion");
Attr attrType = emotiondoc.createAttribute("name");
attrType.setValue("angry");
emotionEl.setAttributeNode(attrType);
emotionEl.appendChild(
emotiondoc.createTextNode("What was that all about?"));
rootElement.appendChild(emotionEl);
} catch (Exception e) {
e.printStackTrace();
}
return emotiondoc;
}
The output of the method as follows,
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<emotionml>
<emotion name="angry">
What was that all about?.
</emotion>
</emotionml>
How can I modify the code to get the right output mentioned in the top of this question??