karthikin Posted July 8, 2011 Share Posted July 8, 2011 <?xml version="1.0" encoding="UTF-8"?><CONTACTS><CONTACT> <PDE-Identity>N676767</PDE-Identity> <FirstName>Dido</FirstName> <LastName>Lorence</LastName> <gmail/> <yahoo>dido.lorence@yahoo.com</yahoo> <alcatel-lucent/> <URL/> <Facebook-ID/></CONTACT></CONTACTS> How can i get the value of my PDE-Identity and delete all the childNodes including the <CONTACT> using Javascript, DOM Method.Thanks Guys! Link to comment Share on other sites More sharing options...
justsomeguy Posted July 8, 2011 Share Posted July 8, 2011 You can't change the file using Javascript, Javascript can read the file and do whatever you want with the data, but it can't change the file and save it again. Link to comment Share on other sites More sharing options...
karthikin Posted July 8, 2011 Author Share Posted July 8, 2011 You can't change the file using Javascript, Javascript can read the file and do whatever you want with the data, but it can't change the file and save it again.HI, I'm able to edit, add new contact in my XML file using java-script. Please have a look at this code:function saveFile(output, savefile) { //var savefile = "c:\\mozdata.txt"; try { netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); } catch (e) { alert("Permission to save file was denied."); } var file = Components.classes["@mozilla.org/file/local;1"] .createInstance(Components.interfaces.nsILocalFile); file.initWithPath( savefile ); if ( file.exists() == false ) { alert( "File Updated Successfully "); file.create( Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 420 ); } var outputStream = Components.classes["@mozilla.org/network/file-output-stream;1"] .createInstance( Components.interfaces.nsIFileOutputStream ); /* Open flags #define PR_RDONLY 0x01 #define PR_WRONLY 0x02 #define PR_RDWR 0x04 #define PR_CREATE_FILE 0x08 #define PR_APPEND 0x10 #define PR_TRUNCATE 0x20 #define PR_SYNC 0x40 #define PR_EXCL 0x80 */ /* ** File modes .... ** ** CAVEAT: 'mode' is currently only applicable on UNIX platforms. ** The 'mode' argument may be ignored by PR_Open on other platforms. ** ** 00400 Read by owner. ** 00200 Write by owner. ** 00100 Execute (search if a directory) by owner. ** 00040 Read by group. ** 00020 Write by group. ** 00010 Execute by group. ** 00004 Read by others. ** 00002 Write by others ** 00001 Execute by others. ** */ outputStream.init( file, 0x04 | 0x08 | 0x20, 420, 0 ); var result = outputStream.write( output, output.length ); outputStream.close();alert( "File Updated Successfully ");clear();} Link to comment Share on other sites More sharing options...
karthikin Posted July 8, 2011 Author Share Posted July 8, 2011 Her is the link: //function from http://puna.net.nz/archives/Code/Mozilla%2...cal%20files.htm Link to comment Share on other sites More sharing options...
justsomeguy Posted July 8, 2011 Share Posted July 8, 2011 If you're using browser-specific things then, yeah, you can save files with certain browsers. It isn't a part of regular Javascript though. Regardless, you can use removeChild to remove nodes from the DOM.http://www.w3schools.com/dom/dom_nodes_remove.asp Link to comment Share on other sites More sharing options...
karthikin Posted July 8, 2011 Author Share Posted July 8, 2011 If you're using browser-specific things then, yeah, you can save files with certain browsers. It isn't a part of regular Javascript though. Regardless, you can use removeChild to remove nodes from the DOM.http://www.w3schools.com/dom/dom_nodes_remove.asp Ok Thank you. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.