Use XML to package website files in ASP

Source: Internet
Author: User

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 CopyCode The Code is as follows: <% @ Language = "VBScript" codePage = "65001" %>
<% Option explicit %>
<% On error resume next %>
<% Response. charset = "UTF-8" %>
<% Server. scripttimeout = 99999999%>
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> script house-Unpack files Program _ Www.jb51.net </title>
</Head>

<Body>
<%
Dim strlocalpath
'Obtain the physical path of the current folder
Strlocalpath = left (request. servervariables ("path_translated"), limit 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 & "<br/>"
Response. Flush
Next
Set objfso = nothing
Set objnodelist = 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 files" & objnodelist (I). Text & "<br/>"
Response. Flush
. Close
End
Set objstream = nothing
Next
Set objnodelist = nothing
End if
End if

Set objxmlfile = nothing

Response. Write "file unwrapped"
%>
</Body>
</Html>

pack. the copy Code code of the ASP package file is as follows: <% @ Language = "VBScript" codePage = "65001" %>
<% option explicit %>
<% on error resume next %>
<% response. charset = "UTF-8" %>
<% server. scripttimeout = 99999999%>




package _ home _ www.jb51.net

<Body>
<%
Dim zippathdir, zippathfile
Dim startime, endtime
'Change the path of the folder to be packaged here
Zippathdir = "D: \ testasp \ dictionary \ xmlpacked \ scrollcolor "'
Zippathfile = "Update. xml"
If right (zippathdir, 1) <> "\" then zippathdir = zippathdir &"\"
'Start Packaging
Createxml (zippathfile)
'Traverse all files and folders in the directory
Sub loaddata (dirpath)
Dim xmldoc
Dim FSO 'fso object
Dim objfolder 'Folder object
Dim objsubfolders
Dim objsubfolder 'subfolders
Dim objfiles
Dim objfile 'file object
Dim objstream
Dim pathname, textstream, PP, xfolder, xfpath, XFile, XPath, xstream
Dim pathnamestr
Response. Write ("============" & dirpath & "===========< br> ")
Set FSO = server. Createobject ("scripting. FileSystemObject ")
Set objfolder = FSO. getfolder (dirpath) 'create a folder object

Response. Write dirpath
Response. Flush

Set xmldoc = server. Createobject ("Microsoft. xmldom ")
Xmldoc. Load server. mappath (zippathfile)
Xmldoc. async = false

'Write 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 "--- <br/>"
Pathnamestr = dirpath & "& objfile. Name
Response. Write pathnamestr &""
Response. Flush
'================================================ ==========
'File writing path and file content
Set XFile = xmldoc. selectsinglenode ("// root"). appendchild (xmldoc. createelement ("file "))
Set XPath = XFile. appendchild (xmldoc. createelement ("path "))
XPath. Text = Replace (pathnamestr, zippathdir ,"")
'Create a file stream to read the file content and write it into the XML file
Set objstream = server. 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
Xstream. datatype = "bin. base64"
Xstream. nodetypedvalue = objstream. Read ()

Set objstream = nothing
Set XPath = nothing
Set xstream = nothing
Set XFile = nothing
'================================================ ==========
End if
Next
Response. Write "<p>"
Xmldoc. Save (server. mappath (zippathfile ))
Set xfpath = nothing
Set xfolder = nothing
Set xmldoc = nothing

'Created subfolder object
Set objsubfolders = 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 to prepare for file writing.
sub createxml (filepath)
'program execution start time
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
%>

Related Article

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: info-contact@alibabacloud.com 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.