使用Ajax修改XML?

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.

Here's how you send xml back to the serverside with javascript:

jQuery.post( 
    url, 
    xml_as_string, 
    success( data, textStatus, jqXHR){

    }, 
    "xml"
);

You can access the XML in javascript with DOMParser

http://www.erichynds.com/jquery/working-with-xml-jquery-and-javascript/

// the correct way to use jQuery w/ XML
// also see http://gist.github.com/553364 for a normalized DOMParser

var 
   // XML string
   xmlString = '<wu_tang><member name="Method Man" /></wu_tang>',

   // DOM parsing object
   parser = new DOMParser(),

   // XML DOM object
   xmlObject = parser.parseFromString(xmlString , "text/xml");

// this is WRONG.  It works, but you're not on an XML DOM
$( xmlString ).find("member").attr("name"); // -> Method Man

// the correct way
$( xmlObject ).find("member").attr("name"); // -> Method Man

// in XHR requests the parsing is automatically done for you by
// the browser.  jQuery passes it into the success callback
$.ajax({
   dataType: 'xml',
   url: 'wutang.xml',
   success: function( XMLObject ){

      // OMG
      $( xmlObject ).find("member").attr("name"); // -> Method Man
   }
});

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.