Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
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
 
Old August 3rd, 2010, 01:54 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
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.
 
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?
 
Old August 4th, 2010, 01:53 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
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.
 
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........





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 09: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 02:32 AM
LOAD A XML FILE FROM JAVASCRIPT nen Javascript How-To 1 December 20th, 2004 11:03 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.