<?xml version="1.0" encoding="gb2312"?>
<GuestBook version="1.0" realese="2060107">
<Record>
<Name>KAI</Name>
<Email>kai@hostx.org</Email>
<Url>http://www.17xml.com </Url>
<Content>千山萬水總是情,常來泡妞行不行?哢哢:_)</Content>
<Time>2006-1-7 11:15:47</Time></Record><Record><Name>jkh</Name><Email>mnmk</Email><Url>kkkii</Url><Content>iuuhhhhhhhh</Content><Time>2006-1-7 11:19:32</Time></Record></GuestBook>
<%@Language="VBScript"%>
<!--#include file="def.asp"-->
<!--#include file="htmlhead.asp"-->
<%
'設定Web頁面的資訊
Response.Buffer = true
Response.Expires = -1
'顯示留言函數init()
'www.knowsky.com
Function init()
entryForm()
'定義局部變數
Dim objXML
Dim arrNames
Dim arrEmails
Dim arrURLS
Dim arrMessages
'建立XMLDOM文檔對象,用來存放留言
Set objXML = server.createObject("Msxml2.DOMDocument")
objXML.async = false
objXML.load(server.MapPath("guestbook.xml"))
'取得留言本各元素的集合
Set arrNames = objXML.getElementsByTagName("Name")
Set arrEmails = objXML.getElementsByTagName("Email")
Set arrURLS = objXML.getElementsByTagName("Url")
Set arrMessages = objXML.getElementsByTagName("Content")
Set arrTimes = objXML.getElementsByTagName("Time")
Response.Write "<table border='0' width='758' bgcolor='#ACB375'>"
Response.Write "<tr><td bgcolor='#ffb442' align='center' height='26'>"
Response.Write "<b>各位的留言如下:</b>"
Response.Write "</td></tr>"
'輸出留言本各元素的內容,最新的留言先顯示
For x=arrNames.length-1 To 0 Step -1
Response.Write "<tr><td>姓名:<a href=mailto:" & arrEmails.item(x).text & ">" & arrNames.item(x).text & "</a></td></tr>"
Response.Write "<tr><td>網址:<a href=" & arrURLS.item(x).text & " target='_blank'>" & arrURLS.item(x).text & "</a><td></tr>"
Response.Write "<tr><td>留言內容:</td></tr>"
Response.Write "<tr><td bgcolor='#ccb442'>" & arrMessages.item(x).text & "</td></tr>"
Response.Write "<tr><td bgcolor='#ccb442'>" & arrTimes.item(x).text & "</td></tr>"
Response.Write "<tr><td> </td></tr>"
Next
Response.Write "</table>"
Set objXML = nothing
End Function
'向XML檔案添加留言記錄的函數addEntry()
Function addEntry()
'定義局部變數
Dim strName
Dim strEmail
Dim strURL
Dim strMessage
'取得留言表單的輸入內容
strName = Request.Form("Name")
strEmail = Request.Form("Email")
strURL = Request.Form("Url")
strMessage = Request.Form("Content")
strTime = Request.Form("Time")
Dim objXML
Dim objEntry
Dim objName
Dim objEmail
Dim objURL
Dim objMessage
Dim objTime
'向XML檔案添加留言內容
Set objXML = server.createObject("Msxml2.DOMDocument")
objXML.async = false
objXML.load(server.MapPath("guestbook.xml"))
Set objEntry = objXML.createNode("element", "Record", "")
objXML.documentElement.appendChild(objEntry)
Set objName = objXML.createNode("element", "Name", "")
objEntry.appendChild(objName)
objName.text = strName
Set objEmail = objXML.createNode("element", "Email", "")
objEntry.appendChild(objEmail)
objEmail.text = strEmail
Set objURL = objXML.createNode("element", "Url", "")
objEntry.appendChild(objURL)
objURL.text = strURL
Set objMessage = objXML.createNode("element", "Content", "")
objEntry.appendChild(objMessage)
objMessage.text = strMessage
Set objTime = objXML.createNode("element", "Time", "")
objEntry.appendChild(objTime)
if strTime="" then
strTime= Now()
end if
objTime.text = strTime
objXML.save(server.MapPath("guestbook.xml"))
Response.Redirect("guestbook.asp")
End function
'填寫和發送留言表單的函數entryForm()
Function entryForm()
Response.Write "<table width='758' border='0' bgcolor='#ACB375'>"
Response.Write "<tr><td>"
Response.Write "<p align='center'><b>訪客留言(XML版)</b></p>"
Response.Write "<hr size='1' color='#847A39' width='100%' noshade>"
Response.Write "<form action=guestbook.asp?action=addEntry method=post>"
Response.Write "<table border='0' align='center'>"
Response.Write "<tr><td>您的姓名:</td><td><input type=text name='Name' /> *必填</td></tr>"
Response.Write "<tr><td>電子郵件:</td><td><input type=text name='Email' /> *選填</td></tr>"
Response.Write "<tr><td>您的Url:</td><td><input type=text name='Url' /> *選填</td></tr>"
Response.Write "<tr><td> </td><td><input type='hidden' name='Time' /></td></tr>"
Response.Write "<tr><td>您的留言:<br />*必填</td><td><textarea name='Content' cols=40 rows=5></textarea></td></tr>"
Response.Write "<tr><td> </td><td><input type=submit value='發布留言' />"
Response.Write " <input type=reset value='取消' /></td></tr>"
Response.Write "</table>"
Response.Write "</form>"
Response.Write "</td></tr>"
Response.Write "</table>"
End Function
%>
<%
'判斷是否發送了留言,並更新留言資訊
Dim a
a = Request.Querystring("action")
If a<>"" Then
addEntry
else
init
End If
%>
<!--#include file="htmlfoot.asp"-->