Can't add node to xml with javascript



I have a little form that i'm gonna use to add node to xml file:


enter image description here


and this is the xml I try to add node to:



<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<data>
<games>
<game id="1">
<name>Bobs Bygg</name>
<difficulty>5</difficulty>
<numberOfRisks>4</numberOfRisks>
<budget>1400000</budget>
<targetGameTime>75</targetGameTime>
<targetDays>85</targetDays>
<numberOfWorkers>5</numberOfWorkers>
<overtimeWorkers>2</overtimeWorkers>
</game>

<game id="2">
<name>Bassams Bygg</name>
<difficulty>2</difficulty>
<numberOfRisks>4</numberOfRisks>
<budget>14000000</budget>
<targetGameTime>75</targetGameTime>
<targetDays>85</targetDays>
<numberOfWorkers>6</numberOfWorkers>
<overtimeWorkers>1</overtimeWorkers>
</game>
</games>
</data>


So i want to make a new "game" node. I have not finished my function to get data from the inputboxes, but my function won't insert anything.



function addGame(){

var xhttp = new XMLHttpRequest();
xhttp.overrideMimeType('text/xml');
xhttp.open("GET", "Data/gameData.xml", false);
xhttp.send(null);
var xmlDoc = xhttp.responseXML;
var newgame = xmlDoc.createElement("gameTest");
xmlDoc.getElementsByTagName("games")[0].appendChild(newgame);
alert("hopefully success");
}


When I debug the code, the xml file gets loaded, and the xmldoc will get the new node inserted, but this won't get saved to the file. I have checked the file on server.


No comments:

Post a Comment