I'm developing a game for a school project and i'd like to save the state of the game in a XML file.
At the moment I'm able to read the info's in the XML file but i can't update it and i don't know why...
Here is the XML:
<story>
<level id="1">
<text>Some info about the level...</text>
<finished>false</finished>
<nbsteps>0</nbsteps>
</level>
</story>
I'd like to edit the <finished>false</finished>
to <finished>true</finished>
as the player finishes this level.
At the moment I've written that code to edit this but it's actually not editing the xml...
public void updateSave(){
try {
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(this.xmlSave);
Element racine = doc.getDocumentElement();
NodeList levelList = doc.getElementsByTagName("level");
Element niveau = (Element) levelList.item(this.levelId);
niveau.getElementsByTagName("finished").item(0).setTextContent("true");
}
catch (ParserConfigurationException | SAXException | IOException | DOMException e) {}
}
Thanks for the explanations and have a nice day!