asp xml 缓存类(2)


Wend
rs.close
Set rs = Nothing
xmlcontent = xmlcontent & " </root>" & vbnewline

Dim folderpath
folderpath = Trim(left(m_XmlFile,InstrRev(m_XmlFile,"\")-1))
Call CreateDIR(folderpath&"") '创建文件夹
WriteStringToXMLFile m_XmlFile,xmlcontent
End Function

'类的私有方法=========================================

Rem 从Xml文件读取数据
Private Function ReadDataFromXml
Dim SQLARR() '数组
Dim XmlDoc 'XmlDoc对象
Dim objNode '子节点
Dim ItemsLength '子节点的长度
Dim AttributesLength '子节点属性的长度
Set XmlDoc=Server.CreateObject("Microsoft.XMLDOM")
XmlDoc.Async=False
XmlDoc.Load(m_XmlFile)
Set objNode=XmlDoc.documentElement '获取根节点
ItemsLength=objNode.ChildNodes.length '获取子节点的长度
For items_i=0 To ItemsLength-1
AttributesLength=objNode.childNodes(items_i).Attributes.length '获取子节点属性的长度
For Attributes_i=0 To AttributesLength-1
ReDim Preserve SQLARR(AttributesLength-1,items_i)
SQLArr(Attributes_i,items_i) = objNode.childNodes(items_i).Attributes(Attributes_i).Nodevalue
Next
Next
Set XmlDoc = Nothing
m_SQLArr = SQLARR
End Function

Rem 从数据库读取数据
Private Function ReadDataFromDB
Dim rs
Dim SQLARR()
Dim k
k=0
Set Rs = Server.CreateObject("Adodb.Recordset")
Rs.open m_sql,m_DataConn,1
If Not (rs.eof and rs.bof) Then
While Not rs.eof
Dim fieldlegth
fieldlegth = rs.Fields.count
ReDim Preserve SQLARR(fieldlegth,k)
Dim fieldi
For fieldi = 0 To fieldlegth-1
SQLArr(fieldi,k) = rs.Fields(fieldi).value
Next
rs.movenext
k=k+1
Wend
End If
rs.close
Set rs = Nothing
m_SQLArr = SQLArr
End Function

'类的辅助私有方法=========================================

Rem 写xml文件
Private Sub WriteStringToXMLFile(filename,str)
Dim fs,ts
Set fs= createobject("scripting.filesystemobject")
If Not IsObject(fs) Then Exit Sub
Set ts=fs.OpenTextFile(filename,2,True)
ts.writeline(str)
ts.close
Set ts=Nothing
Set fs=Nothing
End Sub

Rem 判断xml缓存是否到期
Private Function isXmlCacheExpired(file,seconds)
Dim filelasttime
filelasttime = FSOGetFileLastModifiedTime(file)
If DateAdd("s",seconds,filelasttime) < Now Then
isXmlCacheExpired = True
Else
isXmlCacheExpired = False
End If
End Function

Rem 得到文件的最后修改时间
Private Function FSOGetFileLastModifiedTime(file)
Dim fso,f,s
Set fso=CreateObject("Scripting.FileSystemObject")
Set f=fso.GetFile(file)
FSOGetFileLastModifiedTime = f.DateLastModified
Set f = Nothing
Set fso = Nothing
End Function

Rem 文件是否存在
Public Function FSOExistsFile(file)
Dim fso
Set fso = Server.CreateObject("Scripting.FileSystemObject")
If fso.FileExists(file) Then
FSOExistsFile = true
Else
FSOExistsFile = false

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/2891.html