1 介绍数据库表结构:
表:宾馆-字典-配套设施(id int,name nvarchar(50))
表:宾馆-字典-信用卡 (id int,name nvarchar(50))
表:关键字(keywordid int,typeid,keywordname,selectsql)
insert into 关键字 select 1 , 1,配套设施,select name from 宾馆-字典-配套设施
2 首先把数据从数据库里提取出来,存放成xml文件。
sub updateKeywordFile()
Set rs = db.Execute("SELECT TypeId, TypeName FROM 主表_数据分类 WHERE (ParentId IS NULL) ORDER BY TypeId")
if not(rs.eof or rs.bof) then
do while not rs.eof
xml = getKeywordByCategory(rs("TypeId"))
if xml <> empty then
file = server.MapPath("../data/Keyword_" & rs("TypeId") & ".xml")
On Error Resume Next
set xmldoc = server.CreateObject("MSXML2.DOMDocument")
xmldoc.async = false
xmldoc.loadXML(xml)
xmldoc.save file
if Err.Number <> 0 then
response.Write "Write xml file " & file & " error:"
response.Write Err.Description
response.Write "<br/>"
else
response.Write "Write xml file " & file & " OK<br/>"
end if
Err.Clear
end if
rs.movenext
loop
end if
rs.close
set rs=nothing
end sub
function getKeywordByCategory(categoryId)
dim xml, sql
sql = "SELECT KeywordTypeName, SelectSql FROM 关键字" & _
" WHERE (TypeId = " & categoryId & ") ORDER BY KeywordTypeId"
Set rs1 = db.Execute(sql)
if not(rs1.eof or rs1.bof) then
xml = "<?xml version=""1.0"" encoding=""gb2312""?><Keywords>"
do while not rs1.eof
xml = xml & "<Group Name=" & chr(34) & rs1("KeywordTypeName") & chr(34) & ">"
sql = rs1("SelectSql")
Set rs2 = db.Execute(sql)
if not(rs2.eof or rs2.bof) then
do while not rs2.eof
xml = xml & "<Item Keyword=" & chr(34) & rs2(0) & chr(34) & "/>"
rs2.movenext
loop
end if
rs2.close
set rs2=nothing
xml = xml & "</Group>"
rs1.movenext
loop
xml = xml & "</Keywords>"
end if
rs1.close
set rs1=nothing
getKeywordByCategory = xml
end function
----------------------------------------------
sub updateHotKeywordFile()
dim sql,file
sql = "select Category.TypeId, Category.TypeName, Keyword " & _
"from dbo.关键字_历史记录 as HotKey " & _
"inner join dbo.主表_数据分类 as Category on HotKey.Type=Category.TypeId and Category.ParentId is null " & _
"where datediff(day,LastHitDate,getdate())<30 " & _
"order by Category.TypeId, HitCount desc " & _
"for XML auto"
file = server.MapPath("../data/HotKeyword.xml")
call writeXMLFile(sql, "HotKeys", file)
end sub
sub writeXMLFile(sql, root, file)
On Error Resume Next
set xmldoc = server.CreateObject("MSXML2.DOMDocument")
xmldoc.async = false
Set objCmd = Server.CreateObject("ADODB.Command")
objCmd.ActiveConnection = db
objCmd.Properties("Output Stream") = xmldoc
objCmd.Properties("XML Root") = root
objCmd.CommandText = sql
objCmd.Execute , , adExecuteStream
xmldoc.save file
Set objCmd = Nothing
if Err.Number <> 0 then
response.Write "Write xml file " & file & " error:"
response.Write Err.Description
response.Write "<br/>"
else
response.Write "Write xml file " & file & " OK<br/>"
end if
end sub
3 从xml文件中提取自己需要的内容
<script src="../scripts/prototype.js" type="text/javascript"></script>
<script src="../scripts/updateHouse_new.js" type="text/javascript"></script>
<tr>
<td class="tbt_td">楼盘户型:</td>
<td class="tbt_td" colSpan="3"><textarea οnkeypress="checkTextValid(this, 498)" id="flat" οnblur="if (this.value ==''){this.value='请输入楼盘户型'}"
style="WIDTH: 400px; HEIGHT: 60px" οnclick="if(this.value=='请输入楼盘户型')this.value=''" name="flat" runat="server">请输入楼盘户型</textarea>
<br>
<A οnclick="selectKeyword('flat','户型')" href="javascript:void(0)">选择楼盘户型</A>
</td>
</tr>
<tr>
<td class="tbt_td">室内设施:</td>
<td class="tbt_td" colSpan="3"><textarea οnkeypress="checkTextValid(this, 498)" id="facility" οnblur="if (this.value ==''){this.value='请输入室内设施'}"
style="WIDTH: 400px; HEIGHT: 60px" οnclick="if(this.value=='请输入室内设施')this.value=''" name="facility" runat="server">请输入室内设施</textarea>
<br>
<A οnclick="selectKeyword('facility','室内设施')" href="javascript:void(0)">选择室内设施</A>
</td>
</tr>
http://dl2.csdn.net/down4/20070718/18154613364.js
http://dl2.csdn.net/down4/20070718/18154713146.js