'數據源 Public Property Set Conn(v) Set m_DataConn = v End Property Public Property Get Conn Conn = m_DataConn End Property
'緩存時間 Public Property Let CacheTime(v) m_CacheTime = v End Property Public Property Get CacheTime CacheTime = m_CacheTime End Property
'xml路徑,用絕對地址 Public Property Let XmlFile(v) m_XmlFile = v End Property Public Property Get XmlFile XmlFile = m_XmlFile End Property
'Sql語句 Public Property Let Sql(v) m_Sql = v End Property Public Property Get Sql Sql = m_Sql End Property '返回記錄數組 Public Property Get SQLArr SQLArr = m_SQLArr End Property
'返回讀取方式 Public Property Get ReadOn ReadOn = m_ReadOn End Property
'類的析構=========================================
Private Sub Class_Initialize() '初始化類 m_CacheTime=60*10 '默認緩存時間為10分鐘 End Sub
Private Sub Class_Terminate() '釋放類
End Sub
'類的公共方法=========================================
Rem 讀取數據 Public Function ReadData If FSOExistsFile(m_XmlFile) Then '存在xml緩存,直接從xml中讀取 ReadDataFromXml m_ReadOn=2 Else ReadDataFromDB m_ReadOn=1 End If End Function
Rem 寫入XML數據 Public Function WriteDataToXml If FSOExistsFile(m_XmlFile) Then '如果xml未過期則直接退出 If Not isXmlCacheExpired(m_XmlFile,m_CacheTime) Then Exit Function End If Dim rs Dim xmlcontent Dim k xmlcontent = "" xmlcontent = xmlcontent & "<?xml version=""1.0"" encoding=""gb2312""?>" & vbnewline xmlcontent = xmlcontent & " <root>" & vbnewline k=0 Set Rs = Server.CreateObject("Adodb.Recordset") Rs.open m_sql,m_DataConn,1 While Not rs.eof xmlcontent = xmlcontent & " <item " For Each field In rs.Fields xmlcontent = xmlcontent & field.name & "=""" & XMLStringEnCode(field.value) & """ " Next rs.movenext k=k+1 xmlcontent = xmlcontent & "></item>" & vbnewline Wend rs.close Set rs = Nothing xmlcontent = xmlcontent & " </root>" & vbnewline