Saving XML


You can save XML on the server using the save method, as shown in the following sample ASP file.

<!-- SaveXmlString.asp -->
   If IsEmpty(Request("strXml")) Then
      Msg = "Please enter a brief XML string, such as '&lt;root/&gt;'."
      Dim str, xmldoc
      Set xmldoc = CreateObject("Msxml2.DOMDocument.6.0")
      xmldoc.loadXML Request("strXml")
      If xmlDoc.parseError.errorCode <> 0 Then
          Msg = "The string you entered was not well-formed XML. " & _
          str = Request("strXml")
          str = Replace(str, Chr(38),"&#38;", 1, -1, 1)
          str = Replace(str, Chr(34),"&#34;", 1, -1, 1)
          str = Replace(str, Chr(46),"&#46;", 1, -1, 1)
          str = Replace(str, Chr(60),"&lt;", 1, -1, 1)
          str = Replace(str, Chr(62),"&gt;", 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">
<%= Msg %><BR>
VALUE="<%= Request("strXml")%>"><BR>
<INPUT TYPE="Submit" VALUE="Submit">

Try It!

  1. On your server computer where you are running Internet Information Services (IIS) with ASP enabled, open Notepad.

  2. Copy SaveXmlString.asp from above. Paste it into the Notepad window.

  3. From the File menu, click Save As. Save the file as SaveXmlString.asp to a folder (such as C:\test).

  4. From the Start menu, click Run. Type "inetmgr" to open the Internet Information Services snap-in.

  5. From IIS, navigate to Default Web Site.

  6. Add a new Virtual directory.

  7. 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 or authentication, be sure that the client has write permission to the folder as well as the default permissions (Read, Run scripts).

  8. Using Internet Explorer, open the Web URL (such as "http://MyServer/test/SaveXmlString.asp") to load the page.

  9. Enter a brief well-formed XML string (such as "<root/>") in the form. Click Submit.

System_CAPS_ICON_note.jpg Note

The MapPath method resolves relative paths into the full paths required on the server.


If you enter the suggested XML string ("<root/>"), you should see the following appear in the browser:

Your XML string:  
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.