GDog999
23 May 2011, 05:18 PM
Hello,
I have the following code:
Code:
<script type="text/javascript">
function doUpdate()
{
if (window.XMLHttpRequest)
{
xhttp=new XMLHttpRequest();
}
else
{
xhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("POST", "news.xml", false);
xhttp.send();
xmlDoc = xhttp.responseXML;
// create new entry
newNode = xmlDoc.createElement("entry");
newNode.setAttribute("date", "19/05/2011");
newNode.setAttribute("title", "a title");
x = xmlDoc.documentElement;
y = xmlDoc.getElementsByTagName("entry");
document.write("Elements: " + y.length + "\n");
// insert new entry at the beginning
x.insertBefore(newNode,y[0]);
document.write("Elements: " + y.length + "\n");
document.write("success");
}
</script>
I am opening an XML file and I am then trying to add a new element to the XML tree. How can I write this data, i.e. the old data with the newly created entry, back to the file I opened?
Thank you for your help. :)
I have the following code:
Code:
<script type="text/javascript">
function doUpdate()
{
if (window.XMLHttpRequest)
{
xhttp=new XMLHttpRequest();
}
else
{
xhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("POST", "news.xml", false);
xhttp.send();
xmlDoc = xhttp.responseXML;
// create new entry
newNode = xmlDoc.createElement("entry");
newNode.setAttribute("date", "19/05/2011");
newNode.setAttribute("title", "a title");
x = xmlDoc.documentElement;
y = xmlDoc.getElementsByTagName("entry");
document.write("Elements: " + y.length + "\n");
// insert new entry at the beginning
x.insertBefore(newNode,y[0]);
document.write("Elements: " + y.length + "\n");
document.write("success");
}
</script>
I am opening an XML file and I am then trying to add a new element to the XML tree. How can I write this data, i.e. the old data with the newly created entry, back to the file I opened?
Thank you for your help. :)