You can save XML on the server using the save
method, as shown in the following sample ASP file.
<HTML> <BODY> <!-- SaveXmlString.asp --> <% If IsEmpty(Request("strXml")) Then Msg = "Please enter a brief XML string, such as '<root/>'." Else Dim str, xmldoc Set xmldoc = CreateObject("Msxml2.DOMDocument.5.0") xmldoc.loadXML Request("strXml") If xmlDoc.parseError.errorCode <> 0 Then Msg = "The string you entered was not well-formed XML. " & _ xmlDoc.parseError.reason Else xmldoc.save(Server.MapPath("saved.xml")) str = Request("strXml") str = Replace(str, Chr(38),"&", 1, -1, 1) str = Replace(str, Chr(34),""", 1, -1, 1) str = Replace(str, Chr(46),".", 1, -1, 1) str = Replace(str, Chr(60),"<", 1, -1, 1) str = Replace(str, Chr(62),">", 1, -1, 1) Msg = "<P>Your XML string:<BR>" & str & _ "<BR>has been saved to the server as <B>saved.xml</B>.</P>" End If End If %> <FORM METHOD="POST" ACTION="SaveXmlString.asp"> <PRE> <%= Msg %><BR> <INPUT TYPE="TEXT" NAME="strXml" SIZE=75 VALUE="<%= Request("strXml")%>"><BR> <INPUT TYPE="Submit" VALUE="Submit"> </PRE> </FORM> </BODY> </HTML>
Try It!
Note The MapPath
method resolves relative paths into the full paths required on the server.
Output
If you enter the suggested XML string ("<root/>"), you should see the following appear in the browser:
Your XML string:
<root/>
has been saved to the server as saved.xml
.
You can then open the directory you used in steps 3 and 7 and verify that saved.xml is present.