facebook

Write Data into xml.

  1. MobiOne Archive
  2.  > 
  3. Getting Help – General
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #339612 Reply

    Rathinavel
    Member

    Hi Team,

    I am stuck up with writing data into XML.

    I have used the following code:

    var text = ”;
    //XML Read
    xmlhttp=new XMLHttpRequest();
    xmlhttp.open(“GET”,”AllDetails.xml”,false);
    xmlhttp.setRequestHeader(‘Content-Type’, ‘text/xml’);
    xmlhttp.send();

    xmlDoc=xmlhttp.responseXML;
    alert(‘Started’);
    text = text + ‘<User Name=”‘ + Name +'” ‘+ ‘Age=”‘ + Age +'” ‘+’City=”‘ + City + ‘” ‘;

    text = text + ‘Country=”‘ + Country+ ‘” />’ ;
    alert(text);
    //xmlDoc=loadXMLString(text);

    xmlhttp.open(“POST”,”AllDetails.xml”,true);
    xmlhttp.setRequestHeader(“Content-type”,”text/xml”);
    xmlhttp.send(text);
    alert(‘Finished Writing XML’);

    I dont know where I went wrong. Please help me in this.

    #339687 Reply

    support-michael
    Keymaster

    In your example code is rough but it looks like you trying to perform a GET and POST. Let me propose that you use jQuery to assist since it is available to your project and can simplify some things.

    See jquery functions such as
    $.get() http://api.jquery.com/jQuery.get/
    $.post() http://api.jquery.com/jQuery.post/
    $.ajax() http://api.jquery.com/jQuery.ajax/

    or googling will provide results such as
    http://stackoverflow.com/questions/5176548/different-ways-to-pass-xml-via-jquery-ajax

    To parse an XML string to a DOM that you can manipulate use $.parseXML().
    Example parse xml and get name attribute:
    xmldata = $.parseXML(‘<user name=”octavio” />’)
    xmldata.find(‘user’).attr(‘name’)

Viewing 2 posts - 1 through 2 (of 2 total)
Reply To: Write Data into xml.

You must be logged in to post in the forum log in