ASP+XML全面代替服务器服务,减低服务器负担

'/*===============[使用方法]=================*/'

Dim JianJianJava,TempVariables,VariablesCount
'声明变量

Set JianJianJava = New FreeXml
'创建类

JianJianJava.Data = Server.MapPath('Java.xml')
'设置缓存XML文件的位置,请把Xml文件放在其它路径以加密文件

JianJianJava.XmlApplication('缓存变量名') = '缓存变量值'
'公有变量赋值

TempVariables = JianJianJava.XmlApplication('缓存变量名')
'取出公有变量值

JianJianJava.RemoveApplication '缓存变量名'
'把指定公有变量从XML文件中释放

VariablesCount = JianJianJava.XmlApplicationCount()
'取出已缓存公有变量的个数

JianJianJava.XmlSession('客户变量名') = '缓存变量值'
'私有变量赋值,

TempVariables = JianJianJava.XmlSession('每个变量名')
'取出私有变量值

JianJianJava.RemoveSession '客户变量名'
'把指定私有变量从XML文件中释放

VariablesCount = JianJianJava.SessionCount()
'取出已缓存私有变量的个数

JianJianJava.XmlApplicationContent('数组名',下界数字) = '值'
'下界是数值,公有数组变量赋值

TempVariables = JianJianJava.XmlApplicationContent('数组名',下界数字)
'取出公有数组变量值

JianJianJava.RemoveContent '数组名',下界数字
'把指定集合里的指定变量释放

JianJianJava.RemoveFirst('数组名')
'把指定集合里的第一个变量释放,如果集合里一个变量也没有,会把指定集合释放

JianJianJava.RemoveLast('数组名')
'把指定集合里的最后一个变量释放,如果集合里一个变量也没有,会把指定集合释放

Count = JianJianJava.XmlApplicationCount('数组名')
'返回集合里变量的个数
'/*==========================================*/'
XML文件的写是如下:
'/*==========================================*/'
<?xml version='1.0' encoding='gb2312'?>
<JianJianJava><Application/><Content/><Session/></JianJianJava>
'/*==========================================*/'

作者: 健健(Java)
QQ:   6090900
Email:CoolEase@126.com
欢迎交流

转载或修改时,请保留文件里的版权信息.谢谢.

 

 

======================(XML_Class.asp)ASP源代码文件===============
<%
Class FreeXml
'/*===============[版权声明]=================*/'
'/* Write By:  健健(Java)
'/* QQ Num:   6090900
'/* Email-Address:  CoolEase@126.com
'/* Date:   2004-06-17 23:13
'/* Web-Address:  Have no,Temporarily
'/* Class-Version:  3.0
'/* 转载时或修改时,请尊重作者的知识产权,保留此声明!
'/*==========================================*/'
'//=======[Declare Variables]
Public XmlDom,SoureFile,SessionID,XmlDoc,XmlNode,XmlAttr
'//=======[Set XML-File's Path]
Public Property Let Data(FilePath)
 If Len(FilePath) = 0 Then Response.Write('缓存数据文件路径不能为空'):Exit Property
  SoureFile = FilePath
  SessionID = Session.SessionID
 Set XmlDom = Server.CreateObject('MSXML2.FreeThreadedDOMDocument.4.0')
  XmlDom.Async = False
 If XmlDom.Load(SoureFile) Then
  Data = True
 Else
  Response.Write('缓存数据文件读取失败')
  Data = False
  Set XmlDom = Nothing
 End If
End Property
'//=======[Functions For Filter HTML]
Public Function FilterHTML(Str)
 If Not IsNull(Str) then
  Str = Replace(Str, '>', '&gt;')
  Str = Replace(Str, '<', '&lt;')
  Str = Replace(Str, '&', '&amp;')
  Str = Replace(Str, CHR(32), '&nbsp;')
  Str = Replace(Str, CHR(9), '&nbsp;')
  Str = Replace(Str, CHR(34),'&quot;')
  Str = Replace(Str, CHR(39),'&#39;')
  FilterHTML = Str
 End If
End Function
'//=======[Functions For Application]
Public Property Let XmlApplication(sCacheName,sCacheValue)
 Set XmlDoc = XmlDom.documentElement.selectSingleNode('/JianJianJava/Application/' & sCacheName)
  If XmlDoc Is Nothing Then
   Set XmlDoc = XmlDom.documentElement.selectSingleNode('/JianJianJava/Application')
   Set XmlNode = XmlDom.createElement(sCacheName)
   XmlNode.Text = sCacheValue
   XmlDoc.AppendChild(XmlNode)
  Else
   XmlDoc.Text = sCacheValue
  End If
 XmlDom.Save(SoureFile)
End Property

Public Property Get XmlApplication(sCacheName)
 Set XmlDoc = XmlDom.documentElement.selectSingleNode('/JianJianJava/Application/' & sCacheName)
  If XmlDoc Is Nothing Then
   XmlApplication = ''
  Else
   XmlApplication = XmlDoc.Text
  End If
End Property

Public Function RemoveXmlApplication(sCacheName)
 Set XmlDoc = XmlDom.documentElement.selectSingleNode('/JianJianJava/Application/' & sCacheName)
  If Not(XmlDoc Is Nothing) Then XmlDoc.ParentNode.removeChild(XmlDoc)
 XmlDom.Save(SoureFile)
End Function

Public Property Get XmlApplicationCount()
 Set XmlDoc = XmlDom.documentElement.selectSingleNode('/JianJianJava/Application')
  XmlApplicationCount = XmlDoc.ChildNodes.Length
End Property
'//=======[Functions For Application.Content]
Public Property Let XmlApplicationContent(sArray,sCacheNum,sCacheValue)
If Not IsNumeric(sCacheNum) Then Exit Property
 Set XmlDoc = XmlDom.documentElement.selectSingleNode('/JianJianJava/Content/'&sArray&'/Cache[@ID='&sCacheNum&']')
  If XmlDoc Is Nothing Then
  Set XmlDoc = XmlDom.documentElement.selectSingleNode('/JianJianJava/Content/'&sArray)
   If XmlDoc Is Nothing Then
    Set XmlDoc = XmlDom.documentElement.selectSingleNode('/JianJianJava/Content')
    Set XmlNode = XmlDom.createElement(sArray)
    XmlDoc.AppendChild(XmlNode)
   End If
    Set XmlDoc = XmlDom.documentElement.selectSingleNode('/JianJianJava/Content/'&sArray)
    Set XmlNode = XmlDom.createElement('Cache')
    XmlNode.Text = sCacheValue
    Set XmlAttr = XmlDom.createAttribute('ID')
    XmlAttr.Text = sCacheNum
    XmlNode.setAttributeNode XmlAttr
    XmlDoc.AppendChild(XmlNode)
  Else
   XmlDoc.Text = sCacheValue
  End If
 XmlDom.Save(SoureFile)
End Property

Public Property Get XmlApplicationContent(sArray,sCacheNum)
If Not IsNumeric(sCacheNum) Then Exit Property
 Set XmlDoc = XmlDom.documentElement.selectSingleNode('/JianJianJava/Content/' & sArray & '/Cache[@ID=' & sCacheNum & ']')
  If XmlDoc Is Nothing Then
   XmlApplicationContent = ''
  Else
   XmlApplicationContent = XmlDoc.Text
  End If
End Property

Public Property Get XmlApplicationContentByItem(sArray,sCacheNum)
 Set XmlDoc = XmlDom.documentElement.selectSingleNode('/JianJianJava/Content/' & sArray)
  If XmlDoc Is Nothing Then
   XmlApplicationContentByItem = ''
  Else
   Set XmlNode = XmlDoc.ChildNodes.item(sCacheNum)
   If XmlNode Is Nothing Then XmlApplicationContentByItem = '' Else XmlApplicationContentByItem = XmlNode.Text
  End If
End Property

Public Property Get XmlApplicationContentConut()
 Set XmlDoc = XmlDom.documentElement.selectSingleNode('/JianJianJava/Content/' & sArray)
  If XmlDoc Is Nothing Then
   XmlApplicationContentConut = 0
  Else
   XmlApplicationContentConut = XmlDoc.ChildNodes.Length
  End If
End Property

Public Function RemoveLast(sArray)
 Set XmlDoc = XmlDom.documentElement.selectSingleNode('/JianJianJava/Content/' & sArray)
  If Not(XmlDoc Is Nothing) And XmlDoc.ChildNodes.Length<>0 Then
   XmlDoc.removeChild(XmlDoc.ChildNodes.Item(XmlDoc.ChildNodes.Length - 1))
   XmlDom.Save(SoureFile)
   If XmlDoc.ChildNodes.Length = 0 Then
   XmlDoc.ParentNode.removeChild(XmlDoc)
   XmlDom.Save(SoureFile)
   End If
  End If
End Function

Public Function RemoveFirst(sArray)
 Set XmlDoc = XmlDom.documentElement.selectSingleNode('/JianJianJava/Content/' & sArray)
  If Not(XmlDoc Is Nothing) And XmlDoc.ChildNodes.Length<>0 Then
   XmlDoc.removeChild(XmlDoc.ChildNodes.Item(0))
   XmlDom.Save(SoureFile)
   If XmlDoc.ChildNodes.Length = 0 Then
   XmlDoc.ParentNode.removeChild(XmlDoc)
   XmlDom.Save(SoureFile)
   End If
  End If
End Function

Public Function RemoveXmlApplicationContent(sArry,sCacheNum)
 Set XmlDoc = XmlDom.documentElement.selectSingleNode('/JianJianJava/Content/'&sArray&'/Cache[@ID='&sCacheNum&']')
  If Not(XmlDoc Is Nothing) Then XmlDoc.ParentNode.removeChild(XmlDoc)
 XmlDom.Save(SoureFile)
End Function
'//=======[Functions For Sessions]
Public Property Let XmlSession(sCacheName,sCacheValue)
 Set XmlDoc = XmlDom.documentElement.selectSingleNode('/JianJianJava/Session/Guest[@ID='&SessionID&']/'&sCacheName)
  If XmlDoc Is Nothing Then
   Set XmlDoc = XmlDom.documentElement.selectSingleNode('/JianJianJava/Session/Guest[@ID='&SessionID&']')
    If XmlDoc Is Nothing Then
     Set XmlDoc = XmlDom.documentElement.selectSingleNode('/JianJianJava/Session')
     Set XmlNode = XmlDom.createElement('Guest')
     Set XmlAttr = XmlDom.createAttribute('ID')
     XmlAttr.Text = SessionID
     XmlNode.setAttributeNode XmlAttr
     XmlDoc.AppendChild(XmlNode)
     XmlDom.Save(SoureFile)
    End If
     Set XmlDoc = XmlDom.documentElement.selectSingleNode('/JianJianJava/Session/Guest[@ID='&SessionID&']')
     Set XmlNode = XmlDom.createElement(sCacheName)
     XmlNode.Text = sCacheValue
     XmlDoc.AppendChild(XmlNode)
  Else
   XmlDoc.Text = sCacheValue
  End If
 XmlDom.Save(SoureFile)
End Property

Public Property Get XmlSession(sCacheName)
 Set XmlDoc = XmlDom.documentElement.selectSingleNode('/JianJianJava/Session/Guest[@ID='&SessionID&']/' & sCacheName)
  If XmlDoc Is Nothing Then
   XmlSession = ''
  Else
   XmlSession = XmlDoc.Text
  End If
End Property

Public Function RemoveXmlSession(sCacheName)
 Set XmlDoc = XmlDom.documentElement.selectSingleNode('/JianJianJava/Session/Guest[@ID='&SessionID&']/' & sCacheName)
  If Not(XmlDoc Is Nothing) Then
   Set XmlNode = XmlDoc.ParentNode
   XmlNode.removeChild(XmlDoc)
  Else
   Exit Function
  End If
  If XmlNode.ChildNodes.Length = 0 Then XmlNode.ParentNode.removeChild(XmlNode)
 XmlDom.Save(SoureFile)
End Function

Public Property Get XmlSessionCount()
 Set XmlDoc = XmlDom.documentElement.selectSingleNode('/JianJianJava/Session/Guest[@ID='&SessionID&']')
  If XmlDoc Is Nothing Then
   XmlSessionCount = 0
  Else
   XmlSessionCount = XmlDoc.ChildNodes.Length
  End If
End Property
'//=======[Class Terminate]
Private Sub Class_Terminate()
 If IsObject(XmlNode) Then Set XmlNode = Nothing
 If IsObject(XmlAttr) Then Set XmlAttr = Nothing
 If IsObject(XmlDoc) Then Set XmlDoc = Nothing
 If IsObject(XmlDom) Then Set XmlDom = Nothing
End Sub
End Class
%>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值