How can I generate an xml file and allow the user to save it locally using javascript?

I am creating an XMl document using JavaScript and have to prompt the user to save it on their local machine.

This is the code I have at the moment:

var xmlWindow = window.open("", "");
xmlWindow.document.write("<node>data</node>");

      

This writes the xml to a new window which the user can then press file-> save to load.

  1. Is there an even nicer way to do this?
  2. Is there a way to set the mimeType of the new window so that the xml is displayed correctly?
  3. any way to specify the title, so when the user clicks save, the filename is set correctly?

note: should be compatible with most browsers (IE6, IE7, FF, Chrome).

0


source to share


2 answers


You can send XML via XMLHttpRequest to a script on your server to create an xml file and then set window.location to the location of your new XML file. They will be asked to save it.



+2


source


"save it locally": a tough call if you want to be compatible across browsers. See this post .



TiddlyWiki manages to do this for some browsers (not sure which ones it supports), but only by installing certain files by the user.

0


source







All Articles