0

I am trying to generate a TEXT/XML file from a LOCAL HTML file. I know there are a lot of answers to generating a file locally, usually suggesting using ActiveX object or HTML 5. I'm guessing there is a way to make it work on all browsers (in the end HTML extension is opened by a browser even if it is a LOCAL file) and easily since this is a LOCAL file put in by user himself.

My HTML file will be on client's local machine not accessed via HTTP. It is basically just a form written in HTML that upon "SAVE" command should be generating an XML file in the local disk (anywhere user decides) and saving form's content in.

Any good way?

Karaman
  • 395
  • 1
  • 7
  • 19
  • So let me get this straight: you're trying to first generate a HTML file, and then let the user download that file, after the user submits a form? If that's what you meant, it's entirely possible, but before I post an answer I'd like to verify that's what you're looking for. – Joeytje50 Feb 03 '14 at 11:07
  • Hi Joey, thanks for your time. No download. I will mail an HTML file, he will put on his desktop and open, fill the text fields on the form and hit save. Save will just take those fields and make it an XML file and again save on his local disk. That's all. – Karaman Feb 03 '14 at 11:14
  • It seems you do not want to use any communication whit server. It suppose to just work as desktop application. If this is the case you should go for a desktop client application which client can directly from hi desktop. In other case you must have to get posted data back to your sever, process that and send back xml. – Iqbal Feb 03 '14 at 11:42

2 Answers2

0

One way that I can think of is, the html form elements can be set into class variables and then using the jaxb context you can create an XML file out of it.

Useful Link: http://www.vogella.com/tutorials/JAXB/article.html

Deepak
  • 111
  • 9
0

What you can do is use base64 data-urls (no support for IE9-) to download the file:

First you need to create a temporary iframe element for your file to download in:

var ifrm = document.createElement('iframe');
ifrm.style.display = 'none';
document.body.appendChild(ifrm);

Then you need to define what you want the contents of the file to download to be, and convert it to a base64 data-url:

var html = '<!DOCTYPE html><html><head><title>Foo</title></head><body>Hello World</body></html>';
htmlurl = btoa(html);

and set it as source for the iframe

ifrm.src = 'data:text/x-html;base64,'+htmlurl;
Community
  • 1
  • 1
Joeytje50
  • 18,636
  • 15
  • 63
  • 95