473,721 Members | 1,701 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I update data within an xml childnode using XMLHttpRequest

63 New Member
OK, I'm pretty sure this cannot work because I'm trying to use JavaScript (client-side) to write to an xml file (which is server-side) using XMLHttpRequest.

Can I use PHP do what I'm trying to do?

Here's my code:

The function mySaveFunction( ) is called by clicking the "Update" button, after the user changes the data which is populated in the form fields, which was retrieved via XMLHttpRequest from an XML external file.

I know that XMLHttpRequest can createElement() but can it somehow update the text within the node?

Please help and thanks in advance

Expand|Select|Wrap|Line Numbers
  2.     function mySaveFunction()
  3.     {
  4.         try
  5.         {
  6.             if (window.ActiveXObject)
  7.             {
  8.             logovar[0].childNodes[0].InnerText = document.getElementById('logotextfield').value;
  9.             headingvar[0].childNodes[0].InnerText = document.getElementById('headertextfield').value;
  10.             contentvar[0].childNodes[0].InnerText = document.getElementById('textareafield').value;
  11.             }
  12.             else if(window.XMLHttpRequest)
  13.             {
  14.             logovar[0].childNodes[0].InnerText = document.getElementById('logotextfield').value;
  15.             headingvar[0].childNodes[0].InnerText = document.getElementById('headertextfield').value;
  16.             contentvar[0].childNodes[0].InnerText = document.getElementById('textareafield').value;
  17.             data1 = logovar[0].childNodes[0].InnerText;
  18.             data2 = headingvar[0].childNodes[0].InnerText;
  19.             data3 = contentvar[0].childNodes[0].InnerText;
  20.             XMLHttpRequest.send(data1);
  21.             XMLHttpRequest.send(data2);
  22.             XMLHttpRequest.send(data3);
  23.             } 
  24.             else 
  25.             {
  26.             logovar[0].childNodes[0].InnerText = document.getElementById('logotextfield').value;
  27.             headingvar[0].childNodes[0].InnerText = document.getElementById('headertextfield').value;
  28.             contentvar[0].childNodes[0].InnerText = document.getElementById('textareafield').value;
  29.             }    
  30.         catch(e)
  31.         {
  32.             alert(errorHappendHere);
  33.         }        
  34.     }
  38.     try
  39.     {
  40.         if (window.ActiveXObject)
  41.         {
  42.             var errorHappendHere = "Check Browser and security settings";
  43.             xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
  44.             xmlDoc.async=false;
  45.             xmlDoc.load('xml/badgirls_casting2.xml');
  46.         }
  47.         else if(window.XMLHttpRequest)
  48.         {
  49.             var errorHappendHere = "Error handling XMLHttpRequest request";
  50.             var d = new XMLHttpRequest();
  51.             d.open("GET", 'xml/badgirls_casting2.xml', false);
  52.             d.send(null);
  53.             xmlDoc=d.responseXML;
  54.         } else {
  55.             var errorHappendHere = "Error.";
  56.             xmlDoc = document.implementation.createDocument("","",null);
  57.             xmlDoc.async=false;
  58.             xmlDoc.load('xml/badgirls_casting2.xml');
  59.         }
  60.     }    
  61.     catch(e)
  62.     {
  63.         alert(errorHappendHere);
  64.     }
  65. var logovar=xmlDoc.getElementsByTagName('logo');
  66. var headingvar=xmlDoc.getElementsByTagName('heading');
  67. var contentvar=xmlDoc.getElementsByTagName('content');
  69. document.writeln('<table><tr><td>');
  70. document.writeln("Image: </td><td>");
  71. document.writeln("<input type='textfield' style='position:relative; width:200px;' id='logotextfield' value='" + logovar[0].childNodes[0].nodeValue + "'>");
  72. document.writeln("</td></tr><tr><td>");
  73. document.writeln("Header:</td><td>"); 
  74. document.writeln("<input type='textfield' style='position:relative; width:200px;' id='headertextfield' value='" + headingvar[0].childNodes[0].nodeValue + "'>");
  75. document.writeln("</td></tr><tr><td>");
  76. document.writeln("Content: </td><td>");
  77. for (i=0;i<contentvar.length;i++)
  78.   {
  79.   if (contentvar[i].nodeType==1)
  80.     { 
  81.         document.writeln("<textarea cols='30' rows='30' wrap='hard' id='textareafield["+i+"]'>" + contentvar[i].childNodes[0].nodeValue + "</textarea>");
  82.     }
  83.   }
  84. document.writeln('</td></tr><tr><td colspan="2">');
  85. document.writeln('<input type=button onClick=javascript:mySaveFunction(); value=Update>');
  86. document.writeln('</td></tr></table>');
May 31 '07 #1
1 5300
Tarik Monem
63 New Member
OK, I've found a tutorial on XPath -- http://www.w3schools.com/xquery/xquery_select.asp and the following is what I have changed in my code.

It seems pretty straight forward but it's not working :-(

I have placed this code in the header section of the HTML file. The JavaScript is called when the user clicks on the button "Update" after modifying the fields in the form, for which the fields were retrieved from an external XML file using XMLHttpRequest.

Expand|Select|Wrap|Line Numbers
  2.     <script language="javascript">
  3.     <!--
  4.     function mySaveFunction()
  5.     {
  6.             var errorHappendHere = "Error handling XMLHttpRequest request";
  7.             var d = new XMLHttpRequest();
  8.             d.open("POST", 'xml/badgirls_casting2.xml', true);
  9.             d.send(return <logo> document.getElementById('logotextfield').value; </logo>);
  10.             d.send(return <header> document.getElementById('headertextfield').value; </header>);
  11.             d.send(return <content> document.getElementById('textareafield').value; </content>);
  12.             xmlDoc=d.responseXML;
  13.     }
  14.     //-->
  15.     </script>
Is it not working because the Javascript which writes the two textfields and one textarea, is within a div?

Expand|Select|Wrap|Line Numbers
  2.         <div>
  3.             <script language="javascript" src="js_files/badgirls_casting_module.js"></script>
  4.         </div>
Which produces the code beginning with try -- above?

Is it because the file is already opened to populate the textfields and textarea and therefore cannot be altered?

Shouldn't this fill the nodes of the XML document with the values that have been altered in the respective textfields and textarea with no problem?

Thanx in advance :-)
May 31 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Jarson | last post by:
My JavaScript is trying to POST data to a CGI script (Perl) using XMLHttpRequest. My CGI server gets different data from IE than Mozilla Firefox. // For Mozilla, req = new XMLHttpRequest(); // For IE req = new ActiveXObject("Microsoft.XMLHTTP"); req.onreadystatechange = requestHandler ; // function to handle async response req.open('POST', myURL, true); // use POST req.send('foo=11&bar=22') ;
by: William | last post by:
My first time posting to clj , I have already read http://jibbering.com/faq/#FAQ2_3 before posting. javascript function in question: saveText() is as follows: function saveText( scroll_list, t_area, listToBeUpdated ) { alert( listToBeUpdated.name ); // need to know which list to add the value in textarea back into
by: Stephen Plotnick | last post by:
I'm very new to VB.NET 2003 Here is what I have accomplished: MainSelectForm - Selects an item In a public class I pass a DataViewRow to ItemInformation1 Form ItemInformation2 Form
by: pamelafluente | last post by:
The precious input given by Laurent, Martin, Benjamin about XMLHttpRequest in Javascript, has made me think that perhaps I could improve what I am currently doing by using Ajax. Let's make it simple and schematic, to see if there is a simple Ajax answer to this. A. I have an HTML page which has some pure html/css code representing a GRID of cell. The page may also contain other objects (images, etc). B. On the server I have a windows...
by: John J. Hughes II | last post by:
I have a DataGridView with a TextBoxColumn. I setting the data source to a List<stringvalue in a static class. The list is filled from a background thread. So far all is fine and it works great, at least on my system. The reason I am doing this is some customers are pulling from VPN connections which are slow. This allows the list of rows in the data grid to appear a little quicker while the list which are not used as soon load in...
by: sufian | last post by:
Below is the field where user enters his/her email address and the AJAX post request is sent to the server and the user sees the message: echo("<div id=\"message\" class=\"success\">Thank you! You have been successfully registered.</div>"); within 1.5 seconds. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta...
by: ajaxcoder | last post by:
Hi In my project i had a login form and i am trying to send the username and password to the server for authentication using xmlHttpRequest. Hence i am using POST request but i am unable to send data. I tried sending using GET request and GET is working fine. Here is code snippet function postRequest() { \n\ if(window.ActiveXObject) \n\ xmlHTTPObj = new ActiveXObject('Microsoft.XMLHTTP'); \n\ else if (window.XMLHttpRequest) \n\
by: blintrell | last post by:
<?xml version="1.0" encoding="utf-8"?> <root> <groups> <group gid="1" name="CSM"> <contact cid="1" /> <contact cid="2" /> <contact cid="3" /> <contact cid="4" /> </group> <group gid="2" name="RISIK">
by: GavReynolds | last post by:
Hi All I am writing a program to load in an xml file from the server and create an animation to represent this data (for use as a 'front end' for the data). I have loaded in the XML data into the script no worries. I have also managed to duplicate 1 set of movieclips relating to this data. In this case there are 10 childnodes in the xml therefore 10 clips appear on stage. Each of the childnodes has a different number of their own...
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.