tags:

views:

23

answers:

1

hi there,

I want to modify some data on XML file residing on server side by using javascript.

I'm using following code

var xh;
if(window.XMLHttpRequest)
{
    xh=new XMLHttpRequest();
}
else
{
    xh=new ActiveXObject("Microsoft.XMLHTTP");
}
xh.open("get","books.xml",false);
xh.send("");
var xdoc=xh.responseXML;
var x=xdoc.getElementsByTagName("title");
x[0].getAttributeNode("lang").nodeValue="zh";
xh.save("books.xml");

but its not working

Thanks in advance, Guru

A: 

You can’t edit files on a server using JavaScript (unless your server is running Node.js, but that’s a whole different story). JavaScript is a client-side language; you’ll need a server-side language if you want to write to a file.

Mathias Bynens
thanks for your answer mathias,but could you please make clear few things.I just want to know that when javascript is not able to save xml files then why there are options like "xNode.nodeValue="xyz";"?It could be read only too.thanks,:)
Guru
You can load an XML file into memory, parse its contents, and even change values etc. — but that’s just in memory. To change the actual file, you need a server-side script.
Mathias Bynens