Simple example of developing a message board using XML

Source: Internet
Author: User
Tags define local xml xsl
XML is a text-based meta-markup language. it emphasizes the description of data structures and meanings, and achieves the separation of data content and display styles (xml + xsl ), it is not related to the platform. Because XML emphasizes the description of data content,

XML is a text-based meta-markup language. it emphasizes the description of data structures and meanings, and implements the separation of data content and display styles (xml xsl ), it is not related to the platform.

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

On the other hand, XML files are the data carrier. XML is used as a database and we do not need to visit any database system. we can apply any WEB skills to display our data, such as HTML and FlashMX.

Due to the active participation of various Fortune computing companies in the world, XML is increasingly becoming a new generation of Internet-based data structures.

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:
 

<留言本>
<留言记录>
<留言者姓名> KAI
<电子邮件> Kai@hostx.org
<网址> Http://www.17xml.com
<留言内容> A thousand mountains and rivers are always in love. is it good to pick up a girl? Click here :_)


 
Currently, many servers 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 "))
 
'Get the aggregation 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"













"Response. Write" "  'Output the content of each element in the message book. The latest message is displayed first.For x = arrNames. length-1 To 0 Step-1Response. Write" "Response. Write" "Response. Write" "Response. Write" "Response. Write" "Next  Response. Write"
"
Response. Write"Your comments are as follows:"
Response. Write"
"& ArrNames. item (x). text &"
URL: "& arrURLS. item (x). text &"
Message content:
"& ArrMessages. item (x). text &"
"
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"

XML message body example

"
Response. Write" "
Response. Write ""
 
End Function
%>


XML message example



<%
'Determine whether a message is sent and update the message
Dim
A = Request. Querystring ("action ")
If a <> "" Then
AddEntry
Else
Init
End If
%>


 
The above is a simple example of using XML to develop the message board. it is a complete example. you can add more functions as needed. all the programs are successfully debugged in WIN2000 IIS5.0 IE5.5.


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.