Saving XML
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!
- On your server computer where you are running Internet Information Services (IIS), open Notepad.
- Copy SaveXmlString.asp from above. Paste it into the Notepad window.
- From the File menu, click Save As. Save the file as SaveXmlString.asp to a folder (such as C:\test).
- From the Start menu, click Run. Type "inetmgr" to open the Internet Information Services snap-in.
- From IIS, navigate to Internet Information Services\ <your_Web_server_computer>\Default Web Site.
- From the Action menu, point to New, then click Virtual directory.
- Complete the New Virtual Directory wizard using the following information:
- For Alias, enter the name "test" for your new virtual directory.
- For Directory, browse and select the path (such as "C:\test") that you used in step 3.
- For Access Permissions, be sure to select the Write check box as well as accepting the default permissions (Read, Run scripts).
- Using Internet Explorer, open the Web URL (such as "http://MyServer/test/SaveXmlString.asp") to load the page.
- Enter a brief well-formed XML string (such as "<root/>") in the form. Click Submit.
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.
