Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > BOOK: JavaScript Programmer's Reference
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: JavaScript Programmer's Reference
This is the forum to discuss the Wrox book JavaScript Programmer's Reference by Alexei White ISBN: 978-0-470-34472-9
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: JavaScript Programmer's Reference section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old August 3rd, 2010, 04:42 AM
Registered User
 
Join Date: Aug 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to update Xml file using javascript.

Hi,
I have requirement to update xml file locally javascript.

The html file and xml file are in same directory and i want to update the xml file thrgh html file.

Note: I am reading it through undermention script method:
function loadXMLDoc(dname) {
if (window.XMLHttpRequest) {
xhttp = new XMLHttpRequest();
} else {
xhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
//alert(xhttp);

xhttp.open("GET", 'abc.xml', false);
xhttp.send(null);
return xhttp.responseXML;

}

Now i to edit and update the xml :
function doSubmit(){
xmlDoc = loadXMLDoc("abc.xml");
var len = xmlDoc.getElementsByTagName("original").length;
if( (-1 < currentRow) && (currentRow < len) ) {
alert(document.controlForm.notes.value);
xmlDoc.getElementsByTagName("notes")
[currentRow].childNodes[0].nodeValue = "zuni";
xmlDoc.save("abc.xml");
}

}

But it is not updating the local xml file.

Please help me out ?
how to update xml thrgh javaScript.

I am totally stucked?
Thanks,
Zuned
Reply With Quote
  #2 (permalink)  
Old August 3rd, 2010, 01:54 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,652
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Will only work in MSIE and even then you have to set the security level to allow it.

I don't know if xmlDoc.save() can be used, though.

Might have to be more complex than that.
Reply With Quote
  #3 (permalink)  
Old August 4th, 2010, 12:00 AM
Registered User
 
Join Date: Aug 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

My question still unanswered is there is any way through which i can edit my xml using javascript?
Reply With Quote
  #4 (permalink)  
Old August 4th, 2010, 01:53 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,652
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Of course. You can manipulate the DOM object that you get from loading the XML. Add nodes, remove nodes, change node content, etc. For that matter, create a second DOM object and create all new nodes in it based on the nodes in the original. But what good does that do you if you can't save the result?

Now... You *could* ship the result to a server side process and ask *IT* to save it. That's not hard.
Reply With Quote
  #5 (permalink)  
Old August 5th, 2010, 01:14 AM
Registered User
 
Join Date: Aug 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

yup know wht dom can do ...... but major concern was can we use java script to edit and save xml file at client side only........
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Is XSLT enough to update a local xml file? spring2009 XSLT 19 May 20th, 2009 08:54 AM
Update the node value of XML file Manoj Bisht ASP.NET 3.5 Professionals 6 February 19th, 2009 08:36 AM
how to update a xml file billbillbill XML 2 April 11th, 2007 08:23 AM
update xml file using vbs thesun99 XML 0 March 21st, 2005 01:32 AM
LOAD A XML FILE FROM JAVASCRIPT nen Javascript How-To 1 December 20th, 2004 10:03 AM



All times are GMT -4. The time now is 02:27 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.