0

I have an option in my VBScript page where the user can click and I simply read a XML from a database and then I want to save this XML in his machine.

What I have so far is:

Dim xml: Set xml = Server.CreateObject("MSXML2.DOMDocument.3.0")     
xml.LoadXml(xmlEnvio)

Where xmlEnvio is a variable that contains a XML in string format.

I tried to figure out how to generate and save this file in the client machine but nothing works so far.

This is the closest solution I've found, but it's using LoadFromFile and I need to generate the file before.

Does anybody knows an approach for doing this?

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
Maturano
  • 951
  • 4
  • 15
  • 42

1 Answers1

2

This should work:

<%
xmlEnvio="<primoPiatto>Spaghetti</primoPiatto>" 'USED IN MY TEST

Response.AddHeader "Content-disposition", "attachment; filename=spaghetti.xml"
Response.ContentType = "text/xml"
Response.BinaryWrite(xmlEnvio)
Response.End
%>
Vixed
  • 3,429
  • 5
  • 37
  • 68
  • Hey @Vixed, it worked. I could download the file but somehow it does not display in the browser. I can open it with Notepad++ for example, I can see that the xml is valid. An interesting point is if I open the file with Visual Studio Code, it says that " The file will not be displayed in the editor because it is either binary, very large or uses an unsupported text encoding" – Maturano Oct 19 '16 at 10:46
  • 1
    I've changed the BinaryWrite to Write only and I can open it in Visual Studio Code. The only thing now is that accentuation does not show properly , for example :"Emitꡃomercio de Pissos e Ceramicas LTDA ME" Emit[] should be Emitê – Maturano Oct 19 '16 at 10:57
  • Try using **Response.ContentType = "application/xml;charset=UTF-8"** – Vixed Oct 19 '16 at 12:46
  • I tried, but the invalid character keep being showed – Maturano Oct 19 '16 at 12:51
  • what I have done (and now everything is working fine) was setting the CodePage 65001 to the Response. I ended up in this following link aswell: http://stackoverflow.com/questions/1629437/is-codepage-65001-and-utf-8-the-same-thing – Maturano Oct 19 '16 at 13:35
  • I really don't know how to help you without some row of code.. sorry. – Vixed Oct 19 '16 at 14:24