search
HomeWeb Front-endH5 TutorialA simple example of using XML to develop message boards

xml is a meta-markup language based on text format. It focuses on the description of data structure and data meaning, realizes the separation of data content and display style (xml+xsl), and is platform-independent.

Because XML focuses on the description of data content, it is very meaningful to retrieve data. We will no longer retrieve information that is irrelevant to our requirements like HTML.

On the other hand, XML files are the carrier of data. Using XML as a database does not require access to any database system. We can use any WEB technology to display our data, such as HTML, FlashMX, etc.

Due to the active participation of major computer companies in the world, XML is increasingly becoming a new generation standard 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, website address, and message content of the leaver. Of course, we can also add as much information as needed. The content of the file is as follows:

<?xml version="1.0" encoding="gb2312"?> 
<留言本> 
<留言记录> 
<留言者姓名>KAI</留言者姓名> 
<电子邮件>kai@hostx.org</电子邮件> 
<网址>http://www.17xml.com </网址> 
<留言内容>千山万水总是情,常来泡妞行不行?咔咔:_)</留言内容> 
</留言记录> 
</留言本>

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

<%@Language="VBScript"%> 
<% 
&#39;设置Web页面的信息 
Response.Buffer = true 
Response.Expires = -1 
  
&#39;显示留言函数init() 
&#39;www.knowsky.com
Function init() 
entryForm() 
  
&#39;定义局部变量 
Dim objXML 
Dim arrNames 
Dim arrEmails 
Dim arrURLS 
Dim arrMessages 
  
&#39;创建XMLDOM文档对象,用来存放留言 
Set objXML = server.createObject("Msxml2.DOMDocument") 
objXML.async = false 
objXML.load(server.MapPath("guestbook.xml")) 
  
&#39;取得留言本各元素的集合 
Set arrNames = objXML.getElementsByTagName("留言者姓名") 
Set arrEmails = objXML.getElementsByTagName("电子邮件") 
Set arrURLS = objXML.getElementsByTagName("网址") 
Set arrMessages = objXML.getElementsByTagName("留言内容") 
  
Response.Write "<table border=&#39;0&#39; width=&#39;100%&#39;>" 
Response.Write "<tr><td bgcolor=&#39;#00CCFF&#39; align=&#39;center&#39; height=&#39;26&#39;>" 
Response.Write "<b>各位的留言如下:</b>" 
Response.Write "</td></tr>" 
  
&#39;输出留言本各元素的内容,最新的留言先显示 
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=&#39;_blank&#39;>" & arrURLS.item(x).text & "</a><td></tr>" 
Response.Write "<tr><td>留言内容:</td></tr>" 
Response.Write "<tr><td bgcolor=&#39;#0099ff&#39;>" & arrMessages.item(x).text &"</td></tr>" 
Response.Write "<tr><td> </td></tr>" 
Next 
  
Response.Write "</table>" 
Set objXML = nothing 
End Function 
  
&#39;向XML文件添加留言记录的函数addEntry() 
Function addEntry() 
  
&#39;定义局部变量 
Dim strName 
Dim strEmail 
Dim strURL 
Dim strMessage 
  
&#39;取得留言表单的输入内容 
strName = Request.Form("姓名") 
strEmail = Request.Form("电子邮件") 
strURL = Request.Form("网址") 
strMessage = Request.Form("留言") 
  
Dim objXML 
Dim objEntry 
Dim objName 
Dim objEmail 
Dim objURL 
Dim objMessage 
  
&#39;向XML文件添加留言内容 
Set objXML = server.createObject("Msxml2.DOMDocument") 
objXML.async = false 
objXML.load(server.MapPath("guestbook.xml")) 
  
Set objEntry = objXML.createNode("element", "留言记录", "") 
objXML.documentElement.appendChild(objEntry) 
  
Set objName = objXML.createNode("element", "留言者姓名", "") 
objEntry.appendChild(objName) 
objName.text = strName 
  
Set objEmail = objXML.createNode("element", "电子邮件", "") 
objEntry.appendChild(objEmail) 
objEmail.text = strEmail 
  
Set objURL = objXML.createNode("element", "网址", "") 
objEntry.appendChild(objURL) 
objURL.text = strURL 
  
Set objMessage = objXML.createNode("element", "留言内容", "") 
objEntry.appendChild(objMessage) 
objMessage.text = strMessage 
  
objXML.save(server.MapPath("guestbook.xml")) 
  
Response.Redirect("guestbook.asp") 
  
End function 
  
&#39;填写和发送留言表单的函数entryForm() 
Function entryForm() 
  
Response.Write "<p align=&#39;center&#39;><b>XML 留言本 例子</b></p>" 
Response.Write "<hr color=&#39;#000099&#39; width=&#39;100%&#39; noshade>" 
Response.Write "<form action=guestbook.asp?action=addEntry method=post>" 
Response.Write "<table border=1>" 
Response.Write "<tr><td>您的姓名:</td><td><input type=text name=姓名 /></td></tr>" 
Response.Write "<tr><td>电子邮件:</td><td><input type=text name=电子邮件 /></td></tr>" 
Response.Write "<tr><td>您的网址:</td><td><input type=text name=网址 /></td></tr>" 
Response.Write "<tr><td>您的留言:</td><td><textarea name=留言 cols=40 rows=5></textarea></td></tr>" 
Response.Write "<tr><td> </td><td><input type=submit value=发布留言 /></td></tr>" 
Response.Write "</table>" 
Response.Write "</form>" 
  
End Function 
%> 
<html> 
<head> 
<title>XML 留言例子</title> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 
</head> 
<body> 
<% 
&#39;判断是否发送了留言,并更新留言信息 
Dim a 
a = Request.Querystring("action") 
If a<>"" Then 
addEntry 
else 
init 
End If 
%> 
</body> 
</html>

The above is the use of XML to develop message boards A simple example is just an introduction. You can add more functions as needed. All programs pass debugging on WIN2000+IIS5.0+IE5.5.


Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
H5: Tools, Frameworks, and Best PracticesH5: Tools, Frameworks, and Best PracticesApr 11, 2025 am 12:11 AM

The tools and frameworks that need to be mastered in H5 development include Vue.js, React and Webpack. 1.Vue.js is suitable for building user interfaces and supports component development. 2.React optimizes page rendering through virtual DOM, suitable for complex applications. 3.Webpack is used for module packaging and optimize resource loading.

The Legacy of HTML5: Understanding H5 in the PresentThe Legacy of HTML5: Understanding H5 in the PresentApr 10, 2025 am 09:28 AM

HTML5hassignificantlytransformedwebdevelopmentbyintroducingsemanticelements,enhancingmultimediasupport,andimprovingperformance.1)ItmadewebsitesmoreaccessibleandSEO-friendlywithsemanticelementslike,,and.2)HTML5introducednativeandtags,eliminatingthenee

H5 Code: Accessibility and Semantic HTMLH5 Code: Accessibility and Semantic HTMLApr 09, 2025 am 12:05 AM

H5 improves web page accessibility and SEO effects through semantic elements and ARIA attributes. 1. Use, etc. to organize the content structure and improve SEO. 2. ARIA attributes such as aria-label enhance accessibility, and assistive technology users can use web pages smoothly.

Is h5 same as HTML5?Is h5 same as HTML5?Apr 08, 2025 am 12:16 AM

"h5" and "HTML5" are the same in most cases, but they may have different meanings in certain specific scenarios. 1. "HTML5" is a W3C-defined standard that contains new tags and APIs. 2. "h5" is usually the abbreviation of HTML5, but in mobile development, it may refer to a framework based on HTML5. Understanding these differences helps to use these terms accurately in your project.

What is the function of H5?What is the function of H5?Apr 07, 2025 am 12:10 AM

H5, or HTML5, is the fifth version of HTML. It provides developers with a stronger tool set, making it easier to create complex web applications. The core functions of H5 include: 1) elements that allow drawing graphics and animations on web pages; 2) semantic tags such as, etc. to make the web page structure clear and conducive to SEO optimization; 3) new APIs such as GeolocationAPI support location-based services; 4) Cross-browser compatibility needs to be ensured through compatibility testing and Polyfill library.

How to do h5 linkHow to do h5 linkApr 06, 2025 pm 12:39 PM

How to create an H5 link? Determine the link target: Get the URL of the H5 page or application. Create HTML anchors: Use the <a> tag to create an anchor and specify the link target URL. Set link properties (optional): Set target, title, and onclick properties as needed. Add to webpage: Add HTML anchor code to the webpage where you want the link to appear.

How to solve the h5 compatibility problemHow to solve the h5 compatibility problemApr 06, 2025 pm 12:36 PM

Solutions to H5 compatibility issues include: using responsive design that allows web pages to adjust layouts according to screen size. Use cross-browser testing tools to test compatibility before release. Use Polyfill to provide support for new APIs for older browsers. Follow web standards and use effective code and best practices. Use CSS preprocessors to simplify CSS code and improve readability. Optimize images, reduce web page size and speed up loading. Enable HTTPS to ensure the security of the website.

How to generate links with h5How to generate links with h5Apr 06, 2025 pm 12:33 PM

h5 pages can generate links in two ways: create links manually or use short link services. By manually creating, you just need to copy the URL of the h5 page; through the short link service, you need to paste the URL into the service and then get the shortened URL.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools