0

I have been searching all day, and have found some promising options, that haven't panned out for me (ie. Is it possible to add,delete xml nodes with jquery $.ajax?). I believe my biggest issue is not being overly familiar with AJAX or XML, but here is problem simplified: I need to update a local XML page through an HTML page (without use of PHP or other server-side tools). I am working within a vendor-provided solution (so I cannot modify the product much).

Here's snippets of what I have working: mobileSettings.xml:

<settings>
 <application>
   <firstCase>PublicMonitor</firstCase>
 </application>
</settings>

customSettings.js:

function loadSettings()
{
    $.ajax({
        type: "GET",
        url: '../configurations/mobileSettings.xml',
        dataType: "xml",
        success: function(xml) {
            $(xml).find('firstCase').each(function () {
                startPage.value = $(this).text();
            });
        }
    });
}

What I cannot get to work is also a part of the same .js, but it is for Save. You can see by the commented code a number of failed attempts. (Between the Load and Save, the user can change a simple dropdown box to select a new value.):

function saveSettings()
{
    startP = startPage.value;
    $.ajax({
        type: "PUT",
        url: '../configurations/mobileSettings.xml',
        dataType: "xml",
        success: function(xml) {
            $(xml).find('firstCase').each(function () {
//               $(this).text(startP);
               $(this).attr(startP);
//             $(this).find('firstCase').text("test");
//              $(this).setAttribute("firstCase", "test");
//                var elem = document.createElement('firstCase');
//                xml.find('application').append(elem); // Appends <app></app> to <layout>
//                $(this).find('firstCase').text() = startPage.value;
            });
        }
    });
}

My assumption is that there is nothing here that is sending the data to the XML. I have been searching tirelessly, but I have not found a solution that actually works. Again, I cannot use server-side scripting, so the solution must be AJAX/JQuery/Javascript ... which I do not know will work.

Thanks in advance.

EDIT 07.02.2015

I believe I may not have been as clear as I should have been. My problem lies in changing the .xml file through AJAX, etc. I know how to manipulate the data on the user page, but I need the user to be able to declare a new value which will need to be saved to the existing .xml page. The user has a dropdown menu which will provide them with valid values and upon Submit, the XML file needs to change the firstCase node to something else:

<settings>
 <application>
   <firstCase>PrivateMonitor</firstCase>
 </application>
</settings>

The fiddle provided in the comments (http://jsfiddle.net/py5dvk6e/) works well to create the xml string, but I do not know how to save that string to the .xml file called in the customSettings.js file (above).

Community
  • 1
  • 1
  • try using $.parseXML(xml) instead of $(xml) – Sushil Jul 01 '15 at 22:20
  • Perhaps I am missing something (which is a great possibility), but where; just in general replace each of my $(xml) with $.parseXML(xml)? This did not seem to do what I wanted it to, but, again, it could be my lack of knowledge on the subject. I checked out [link]http://api.jquery.com/jQuery.parseXML/[link], but it did not provide me with a way to actually change the XML. I can manipulate the data within the .js/.htm, but it's the actual saving of these changes (to the XML) where my head hurts. Thank you, and sorry for my ignorance. – user2785424 Jul 01 '15 at 22:44
  • try this http://jsfiddle.net/py5dvk6e/ – Sushil Jul 01 '15 at 23:15
  • I have played with the fiddle for the past couple hours and am still having the same issue. I am going to edit my original to perhaps clarify my problem a little better. The fiddle worked as I would expect, but it is the modification of the .xml file itself where I am broken. (Everything is client-side, I would think this should be do-able, but this is far from my area of confidence. – user2785424 Jul 02 '15 at 15:44
  • firstly your xml is not well formed. you need to see the tags properly. the tags are open but they're never closed. your xml is not valid and that is probably why you're not able to update it – Sushil Jul 02 '15 at 15:59
  • Sorry, that was just my lack of proofreading. My actual .xml is better formatted (I will edit the above). I am pretty sure I just came across the same problem (http://stackoverflow.com/a/13073263/) which seems to have been stymied completely ... hoping there is a way to do this, but losing hope. – user2785424 Jul 02 '15 at 16:15
  • so u want to write the xml back on the client side after updating in jquery right? – Sushil Jul 02 '15 at 16:19
  • Precisely. I need the actual XML file to be updated (through a client-side/local tool). – user2785424 Jul 02 '15 at 16:25
  • yeah you can do that but only on chrome. chrome has the filesystem api that lets you save files on the client system but this HTML5 feature is only supported in chrome as of now – Sushil Jul 02 '15 at 16:26
  • Dang. I'm assuming there is no way to emulate the api for other browsers; I guess I need to come up with another plan then. Thank you. – user2785424 Jul 02 '15 at 16:33
  • nope. even i was looking for an alternative for FileSystem API on other browsers but was unable to find it. you can use a java applet then if u want to update the xml n save it on the client side – Sushil Jul 02 '15 at 16:36

0 Answers0