#1 2015-01-15 10:03:00

karolina
Member
Registered: 2014-08-09

Saving xml as a file

Hi,

I have created a script report and one of the export format is xml. I would like to save the xml file on a hard disk.
Currently, after export, the xml is displayed in another tab of a web browser (Firefox).
How to make it saved as file?

Cheers,

Karolina

Offline

#2 2015-01-15 10:30:23

Thorsten J. Krause
Guest

Re: Saving xml as a file

Hi Karolina,

you are probably using something like

return new CompiledXmlReport(writer.toString())

to return the report results, right?
Try replacing this with

return new CompiledXmlReport(writer.toString()){
	@Override
	public String getMimeType() {
		return "application/octet-stream";
	}
}

what happens here is that we override the correct mimetype (which is what the browser uses to decide how to handle a file) with something generic. So the browser no longer knows that the dowloaded file is a xml file and does not try to display it. It's kind of a hack (the correct approach would be to set a Content-disposition header, but you cant do this from a scriptreport (yet)), but it should do it.

Cheers,
Thorsten

#3 2015-01-15 10:48:10

karolina
Member
Registered: 2014-08-09

Re: Saving xml as a file

It works smile - thanks a lot!

Karolina

Offline

Board footer

Powered by FluxBB