'数据源 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