Node.setTextContent() を使用してノードを編集していますが、ファイル内の何も変更していません。テキストの内容を印刷すると、変更されたように表示されますが、プログラムを閉じた後は保持されません。
for (int y=0; y<calendarDataNode.getChildNodes().getLength(); y++) {
//if (year node name == "y" + current year)
if (calendarDataNode.getChildNodes().item(y).getNodeName().equals("y" + Main.year)) {
//for (int m=0; m<number of child nodes of year node; m++)
for (int m=0; m<calendarDataNode.getChildNodes().item(y).getChildNodes().getLength(); m++) {
//if (month node name == "m" + current month)
if (calendarDataNode.getChildNodes().item(y).getChildNodes().item(m).getNodeName().equals("m" + (Main.month_index-1))) {
//for (int d=0; d<number of child nodes of month node; d++)
for (int d=0; d<calendarDataNode.getChildNodes().item(y).getChildNodes().item(m).getChildNodes().getLength(); d++) {
//label node
node = calendarDataNode.getChildNodes().item(y).getChildNodes().item(m).getChildNodes().item(d).getChildNodes().item(0);
node.setTextContent(tf_label.getText());
}
}
}
}
}
try (FileOutputStream outStream = new FileOutputStream("Calendar.xml")) {
Transformer tf = TransformerFactory.newInstance().newTransformer();
tf.setOutputProperty(OutputKeys.INDENT, "yes");
tf.setOutputProperty(OutputKeys.METHOD, "xml");
tf.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
DOMSource domSource = new DOMSource(xmlDoc);
StreamResult sr = new StreamResult(outStream );
tf.transform(domSource, sr);
} catch (TransformerException | IOException e) {e.printStackTrace(System.out);}