How to package website files using xml in asp

Source: Internet
Author: User
Tags servervariables
Today, I checked the content such as packaging files and folders in xml on the Internet and debugged them on the local machine, it seems quite helpful. today I found the content on the Internet, such as packaging files and folders with xml, and debugged it on the local machine.

This method can package the entire folder into an xml file. after the xml file and package file are put together, run the unpackage file to release the original file, in this way, we can package the website and upload it to the VM, and then run the unpackage file. I chose a small number of files for local testing, but I don't know how efficient the execution is in many file situations.
In fact, the implementation idea is also very simple, mainly using the principle that xml files can store binary data. If you are interested, you can download the following attachment study !!
Unpack files

The code is as follows:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%> <% Option Explicit %> <% On Error Resume Next %> <% Response.Charset="UTF-8" %> <% Server.ScriptTimeout=99999999 %>
  Script house -- unpacking program _  <% Dim strLocalPath 'obtain the physical path of the current folder, strLocalPath = Left (Request. serverVariables ("PATH_TRANSLATED"), faster Rev (Request. serverVariables ("PATH_TRANSLATED"), "\") Dim objXmlFile Dim objNodeList Dim objFSO Dim objStream Dim I, j Set objXmlFile = Server. createObject ("Microsoft. XMLDOM ") objXmlFile. load (Server. mapPath ("update. xml ") If objXmlFile. readyState = 4 Then If objXmlFile. parseError. errorCode = 0 Then Set objNodeList = objXmlFile.doc umentElement. selectNodes ("// folder/path") Set objFSO = CreateObject ("Scripting. fileSystemObject ") j = objNodeList. length-1 For I = 0 To j If objFSO. folderExists (strLocalPath & objNodeList (I ). text) = False Then objFSO. createFolder (strLocalPath & objNodeList (I ). text) End If Response. write "create directory" & objNodeList (I ). text &"
"Response. flush Next Set objFSO = nothing Set objNodeList = objXmlFile.doc umentElement. selectNodes ("// file/path") j = objNodeList. length-1 For I = 0 To j Set objStream = CreateObject ("ADODB. stream ") With objStream. type = 1. open. write objNodeList (I ). nextSibling. nodeTypedvalue. saveToFile strLocalPath & objNodeList (I ). text, 2 Response. write "release file" & objNodeList (I ). text &"
"Response. Flush. Close End With Set objStream = Nothing Next Set objNodeList = nothing End If Set objXmlFile = Nothing response. write" file unwrapped "%>

Pack. asp package file

The code is as follows:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%> <% Option Explicit %> <% On Error Resume Next %> <% Response.Charset="UTF-8" %> <% Server.ScriptTimeout=99999999 %>
  Package package _ scripts _  <% Dim ZipPathDir, ZipPathFile Dim startime, endtime' change the path of the folder to be packaged in ZipPathDir = "D: \ testasp \ dictionary \ xmlPacked \ scrollColor" 'zippathfile = "update. xml "if right (ZipPathDir, 1) <>" \ "then ZipPathDir = ZipPathDir &" \ "'start to package CreateXml (ZipPathFile) 'traverse all files in the directory and the folder sub LoadData (DirPath) dim XmlDoc dim fso 'fso object dim objfolder' folder object dim objSubFolders 'subfolders 'collection of dim objfile' subfolders dim objfile' file set dim objfile' file object dim objStream dim pathname, textStream, pp, Xfolder, Xfpath, Xfile, Xpath, Xstream dim PathNameStr response. write ("==========" & DirPath & "============
") Set fso = server. createObject ("scripting. filesystemobject ") set objFolder = fso. getFolder (DirPath) 'creates a folder object Response. write DirPath Response. flush Set XmlDoc = Server. createObject ("Microsoft. XMLDOM ") XmlDoc. load Server. mapPath (ZipPathFile) XmlDoc. async = false' write to each folder path set Xfolder = XmlDoc. selectSingleNode ("// root "). appendChild (XmlDoc. createElement ("folder") Set Xfpath = Xfolder. appendChild (XmlDoc. createElement ("path") Xfpath. text = replace (DirPath, ZipPathDir, "") set objFiles = objFolder. files for each objFile in objFiles if lcase (DirPath & objFile. name) <> lcase (Request. serverVariables ("PATH_TRANSLATED") then Response. write "---
"PathNameStr = DirPath &" & objFile. name Response. write PathNameStr & "" Response. flush '================================================= ========== 'set Xfile = XmlDoc. selectSingleNode ("// root "). appendChild (XmlDoc. createElement ("file") Set Xpath = Xfile. appendChild (XmlDoc. createElement ("path") Xpath. text = replace (PathNameStr, ZipPathDir, "") 'creates a file stream to read the file content and writes it to the Set objStream = Server in the XML file. createObject ("ADODB. stream ") objStream. type = 1 objStream. open () objStream. loadFromFile (PathNameStr) objStream. position = 0 Set Xstream = Xfile. appendChild (XmlDoc. createElement ("stream") Xstream. setAttribute "xmlns: dt", "urn: schemas-microsoft-com: datatypes" 'file content is stored in binary format. dataType = "bin. base64 "Xstream. nodeTypedValue = objStream. read () set objStream = nothing set Xpath = nothing set Xstream = nothing set Xfile = nothing '================== ====================================== end if next Response. write"

"XmlDoc. save (Server. mappath (ZipPathFile) set Xfpath = nothing set Xfolder = nothing set XmlDoc = nothing 'created subfolders = objFolder. subfolders 'Call recursive traversal of Subfolders for each objSubFolder in objSubFolders pathname = DirPath & objSubFolder. name & "\" LoadData (pathname) next set objFolder = nothing set objSubFolders = nothing set fso = nothing end sub 'create an empty XML file, prepare the sub CreateXml (FilePath) program for file writing. the execution time is startime = timer () dim XmlDoc, Root Set XmlDoc = Server. createObject ("Microsoft. XMLDOM ") XmlDoc. async = False Set Root = XmlDoc. createProcessingInstruction ("xml", "version = '1. 0 'encoding= 'utf-8' ") XmlDoc. appendChild (Root) XmlDoc. appendChild (XmlDoc. createElement ("root") XmlDoc. save (Server. mapPath (FilePath) Set Root = Nothing Set XmlDoc = Nothing LoadData (ZipPathDir) 'program end time endtime = timer () response. write ("page Execution time:" & FormatNumber (endtime-startime), 3) & "seconds") end sub %>

The preceding section describes how to package website files in xml under asp. For more information, see other related articles in the first PHP community!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.