So I have a project where I am using an XML document to store data that will be used by several users. User will need to read the contents of the XML, make changes by adding or removing elements, and then save the XML for others to see.
The problem that I am having has to do with browsers caching the XML file. Because of this, a user can successfully read, change, and save a document without other users seeing the changes. Even the user that makes the changes cannot access the new file by default. The server file has changed successfully, but users are viewing the cached file rather than the most recent version.
As I understand it, if the version of the file changes that should force a browser to use the higher version rather than the cached version. However, I can't figure out how to change the version number of the XML file I am saving. Even if I manually change the version of my XML document, my code changes it back to "1.0" and I don't know why or how.
Here is my javascript that alters the XML:
/*-------
This function modifies the XMLDoc which stores the xml information from
users/logins.xml
It then calls SaveData() to write the modified information to file
-------*/
function RemoveFromXML(attribute){
/*-------
This is the tag we will be removing
-------*/
var removeElement = XMLDoc.getElementsByTagName(attribute)[0];
/*-------
This removes the element from the document
-------*/
removeElement.parentNode.removeChild(removeElement);
/*-------
Now we save the document with the new changes
-------*/
SaveData();
}
/*-------
Updates the users/logins.xml document
-------*/
function SaveData(){
/*-------
Data to Save and file at which to save
-------*/
var sendData = "This is new data";
var path = "saveUserXML.php";
/*-------
Create the data based upon the contents of XMLDoc
-------*/
sendData = new XMLSerializer().serializeToString(XMLDoc);
/*-------
Send the "sendData" to the php file
-------*/
xmlhttp.open("POST",path,false);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("a="+sendData);
}
And my PHP file that actually writes the XML:
<?php
$myfile = fopen("users/logins.xml", "w+");
fwrite($myfile, $_POST['a']);
fclose($myfile);
echo "Finished.";
?>
Again, my goal is to prevent users from viewing the cached version of the XML file when the file has been changed. If there is a better way than changing the version after every alteration I would be open to that.