我想在一个父级中编写几个元素,我有以下代码:
public void writeElement(String parent, String element, String content) {
try {
xmlModifier.bind(vtdNav);
vtdNav.toElement(VTDNav.FC, parent);
xmlModifier.insertAfterHead("<" + element + ">" + content + "</" + element + ">");
xmlModifier.output(filepath);
} catch (ModifyException | NavException | IOException | TranscodeException e) {
e.printStackTrace();
}
}
和调用方法:
@FXML
public void save() {
String surname = surnameField.getText();
String name = nameField.getText();
String patronymic = patronymicField.getText();
String id = idField.getText();
String diagnosis = diagnosisArea.getText();
String comments = commentsArea.getText();
dbFile = DBFile.setDoc(dbDir + dbChoiceBox.getValue(), false);
dbFile.writeElement("db", "patient", "");
dbFile.writeElement("patient", "surname", surname);
dbFile.writeElement("patient", "name", name);
dbFile.writeElement("patient", "patronymic", patronymic);
dbFile.writeElement("patient", "id", id);
dbFile.writeElement("patient", "diagnosis", diagnosis);
dbFile.writeElement("patient", "comments", comments);
}
而是这个结果:
<db>
<patient>
<surname></surname>
<name></name>
...
</patient>
</db>
我只有这个:
<db>
<patient>
<comments></comments>
</patient>
</db>
看起来writeElement
每次都重写相同的元素。为什么会发生这种情况,我该如何解决?