I need to paste int XML file several elements in one time, so I have the code:
public void writeElement(String parent, String element, String content) {
try {
xmlModifier = new XMLModifier();
xmlModifier.bind(vtdNav);
vtdNav.toElement(VTDNav.FIRST_CHILD, parent);
xmlModifier.insertAfterHead("<" + element + ">" + content + "</" + element + ">");
xmlModifier.output(filepath);
xmlModifier.remove();
} catch (ModifyException | NavException | IOException e) {
e.printStackTrace();
}
}
I call this method several times sequentially:
dbFile.writeElement("patient", "surname", surname);
dbFile.writeElement("patient", "name", name);
dbFile.writeElement("patient", "patronymic", patronymic);
But the result is:
<db>
<patient>
<patronymic></patronymic>
</patient>
</db>
Why only the last calling of method is executing? And how to change the code to fix the problem?