How do I modify a value in a XML file using JavaScript/Ajax?
I am able to open the XML file with Ajax, and use it’s values in my script, but now I want to send the changes made by my script back to the XML file on the server using Ajax.
It should be possible I think but I can’t find an example to learn from. I have followed a lot of tutorials (also from http://lynda.com), but usually they use data from XML and they dont change it.
I prefer not to use other languages because it’s a very simple script and XML file, containing only 4 fields.
using javascript you can change the xml values and their attributes of their required nodes.
first you need to get the required node from the xml either by getElementbyname or using javascript xquery.
like example check xml from link http://www.w3schools.com/xml/default.asp
suppose i have value xml_item = that have that xml.
Like i want to change the value of tag.
then i do this to change value.
var element_to = xml.getElementsByName(‘To’)[0];
//To change its value first detect borwser if it is I.E then use
element_to.text = “your new value”
//if it is not i.e then use.
element.to.textContent = “your new value”;
//if you want to change property value of element you need to do this.
element_to.setAttribute(“attibute_name”,”new_value”);
I hope that you will understand that.