Simple instance code parsing for message board development using XML

Source: Internet
Author: User
Tags xsl
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. 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:

  
 <留言本> 
  <留言记录> 
   <留言者姓名>
    
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 :_)
    
   
   

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

<% @ Language = "VBScript" %> <% 'sets the webpage information Response. buffer = true Response. expires =-1 'display the message function init () 'www. knowsky. comFunction init () entryForm () 'defines the local variable Dim objXML Dim arrNames Dim arrEmails Dim arrURLS Dim arrMessages' to create the XMLDOM document object and store the message Set objXML = server. createObject ("Msxml2.DOMDocument") objXML. async = false objXML. load (server. mapPath ("guestbook. xml ") 'gets the Set arrNames = objXML of each element in the message base. 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 base. The latest message is first displayed as For x = arrNames. length-1 To 0 Step-1 Response. 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" adds the message record Function addEntry () to the XML file () 'define the local variable Dim strName Dim strEmail Dim strURL Dim strmessage' to obtain 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 the message content Set objXML = server to the XML file. 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 'specifies the entryForm () Function entryForm () Response. write"

XML message body example

"Response. Write" "Response. Write" "End Function %> XML message example <% 'Determines whether a message is sent and updates 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 simple example. you can add more functions as needed. all programs are debugged in WIN2000 + IIS5.0 + IE5.5.

The above section uses XML to develop simple instance code parsing content on the message board. For more information, see PHP Chinese website (www.php1.cn )!

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.