Simple example of developing a message board using XML

Source: Internet
Author: User
Tags define local

XML is a text-format-based meta-markup language that focuses on the description of the data structure and meaning, and achieves the separation of data content and display styles (XML + XSL ), it is not related to the platform.

Because XML focuses on the description of data content, it is very meaningful for data retrieval, and we will not retrieve information unrelated to our requirements like HTML.

On the other hand, XML files are the data carrier. XML is used as a database, without access to any database system. We can use any web technology to display our data, such as HTML and flashmx.

Due to the active participation of various computer companies in the world, XML is increasingly becoming a new generation of standards for Internet-based data formats.

The following uses XML as the data carrier to develop an XML-based message board.

First, we create the XML file guestbook. XML, which records the name, email, URL, and message content of the message recipient. Of course, we can also add any amount of information as needed. The file content is as follows:

<? XML version = "1.0" encoding = "gb2312"?>
<Message book>
<Message record>
<Name of the message body> Kai </Name of the message body>
<Email> kai@hostx.org </Email>
<Web site> http://www.17xml.com </web site>
<Message content> is it true that you can always pick up a girl? Click here: _) </message content>
</Message record>
</Message book>

Because many servers currently support ASP, we use common ASP as the implementation tool. The guestbook. asp file is as follows:

<% @ Language = "VBScript" %>
<%
'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 ("message holder name ")
Set arremails = objxml. getelementsbytagname ("email ")
Set arrurls = objxml. getelementsbytagname ("url ")
Set arrmessages = objxml. getelementsbytagname ("message content ")

Response. Write "<Table border = '0' width = '000000'>"
Response. Write "<tr> <TD bgcolor = '# 00ccff' 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> <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 = '# 0099ff'>" & arrmessages. 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 ("message ")

Dim objxml
Dim objentry
Dim objname
Dim objemail
Dim objurl
Dim objmessage

'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", "message record ","")
Objxml.doc umentelement. appendchild (objentry)

Set objname = objxml. createnode ("element", "message holder 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", "message content ","")
Objentry. appendchild (objmessage)
Objmessage. Text = strmessage

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 "<p align = 'center'> <B> XML Message Body example </B> </P>"
Response. Write "<HR color = '#000099 'width = '000000' noshade>"
Response. Write "<form action = guestbook. asp? Action = addentry method = post>"
Response. Write "<Table border = 1>"
Response. Write "<tr> <TD> your name: </TD> <input type = text name = Name/> </TD> </tr>"
Response. Write "<tr> <TD> Email: </TD> <input type = text name = Email/> </TD> </tr>"
Response. Write "<tr> <TD> your website: </TD> <input type = text name = URL/> </TD> </tr>"
Response. write "<tr> <TD> your message: </TD> <textarea name = message Cols = 40 rows = 5> </textarea> </TD> </tr>"
Response. Write "<tr> <TD> </TD> <input type = submit value = publish message/> </TD> </tr>"
Response. Write "</table>"
Response. Write "</form>"

End Function
%>
<HTML>
<Head>
<Title> XML message example </title>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
</Head>
<Body>
<%
'Determine whether a message is sent and update the message
Dim
A = request. querystring ("action ")
If a <> "" then
Addentry
Else
Init
End if
%>
</Body>
</Html>

The above is a simple example of using XML to develop a message board. It is a simple example. You can add more functions as needed. All Program Debugging in Win2000 + iis5.0 + ie5.5 is successful.

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.