Slightly changed an ASP + XML simple message book on the Internet

Source: Internet
Author: User
Tags define local

 

<? 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> is it possible to pick up a girl? Click restart: _) </content>
<Time> 11:15:47 </time> </record> <Name> jkh </Name> <email> mnmk </Email> <URL> kkkii </URL> <content> iuuhhhhhhhh </content> <time> 11:19:32 </time> </record> </guestbook>

<% @ Language = "VBScript" %>

<! -- # Include file = "def. asp" -->
<! -- # Include file = "htmlhead. asp" -->
<%
'Set the web page information
Response. Buffer = true
Response. expires =-1

'Display message function Init ()
'Www .knowsky.com
Function Init ()
Entryform ()
 
'Define local variables
Dim objxml
Dim arrnames
Dim arremails
Dim arrurls
Dim arrmessages
 
'Create an xmldom Document Object to store messages
Set objxml = server. Createobject ("msxml2.domdocument ")
Objxml. async = false
Objxml. Load (server. mappath ("guestbook. xml "))
 
'The collection of each element in the message book
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 = '000000' bgcolor = '# acb375'>"
Response. Write "<tr> <TD bgcolor = '# ffb442' align = 'center' Height = '26'>"
Response. Write "<B> your comments are as follows: </B>"
Response. Write "</TD> </tr>"
 
'Output the content of each element in the message book. The latest message is displayed first.
For x = arrnames. Length-1 to 0 step-1
Response. write "<tr> <TD> name: <a href = mailto:" & arremails. item (X ). text & ">" & arrnames. item (X ). text & "</a> </TD> </tr>"
Response. write "<tr> <TD> URL: <a href =" & arrurls. item (X ). text & "target = '_ blank'>" & arrurls. item (X ). text & "</a> <TD> </tr>"
Response. Write "<tr> <TD> message content: </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> </tr>"
Next
 
Response. Write "</table>"
Set objxml = nothing
End Function
 
'Function for adding a message record to the XML file addentry ()
Function addentry ()
 
'Define local variables
Dim strname
Dim stremail
Dim strurl
Dim strmessage
 
'Get the input content of the message form
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
 
'Add message content to the XML file
Set objxml = server. Createobject ("msxml2.domdocument ")
Objxml. async = false
Objxml. Load (server. mappath ("guestbook. xml "))
 
Set objentry = objxml. createnode ("element", "record ","")
Objxml.doc umentelement. 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
 
'Fill in and send the message form function entryform ()
Function entryform ()
Response. Write "<Table width = '000000' border = '0' bgcolor = '# acb375'>"
Response. Write "<tr> <TD>"
Response. Write "<p align = 'center'> <B> visitor message (XML version) </B> </P>"
Response. Write "<HR size = '1' color = '#847a39' width = '000000' noshade>"
Response. Write "<form action = guestbook. asp? Action = addentry method = post>"
Response. Write "<Table border = '0' align = 'center'>"
Response. write "<tr> <TD> your name: </TD> <input type = text name = 'name'/> * required </TD> </tr>"
Response. write "<tr> <TD> Email: </TD> <input type = text name = 'email '/> * optional </TD> </tr>"
Response. write "<tr> <TD> your url: </TD> <input type = text name = 'url'/> * optional </TD> </tr>"
Response. Write "<tr> <TD> </TD> <input type = 'did' name = 'time'/> </TD> </tr>"
Response. write "<tr> <TD> your message: <br/> * required </TD> <textarea name = 'content' Cols = 40 rows = 5> </textarea> </TD> </tr>"
Response. Write "<tr> <TD> </TD> <input type = submit value = 'Publish message'/>"
Response. Write "<input type = reset value = 'cancel'/> </TD> </tr>"
Response. Write "</table>"
Response. Write "</form>"
Response. Write "</TD> </tr>"
Response. Write "</table>"
End Function
%>

<%
'Determine whether a message is sent and update the message
Dim
A = request. querystring ("action ")
If a <> "" then
Addentry
Else
Init
End if
%>

 

<! -- # Include file = "htmlfoot. asp" -->

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.