XML (Extensible Markup Language) is a 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, and is independent of the platform. The following uses XML as the carrier of data to develop an XML-based message board.
XML (Extensible Markup Language) is a 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, and is independent of the platform. Since XML focuses on the description of data content, it is very meaningful for data retrieval. We will no longer retrieve information that is not related 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, Flash 5, etc. Thanks to the active participation of major computer companies around the world, XML is increasingly becoming the standard for the next generation of Internet-based data formats. The following uses XML as the carrier of data 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 commentator. Of course, we can also add as much information as we need.
The file contents are as follows:
- <?xmlversion=1.0encoding=gb2312?>
- <Message Book>
- <Message Record>
- <Name of the commentator>Meng Xianhui</Name of the commentator>
- <Email>[email protected]</Email>
- <Website>http://go.163.com/~colorweb</website>
- <Message Content> Tested successfully! ! </Message Content>
- </Message Record>
- </Message Book>
Since many servers currently support ASP, we use common ASP as implementation tool. The guestbook.asp file is as follows:
- <%@Language=VBScript%>
- <%
- 'Set the information of the web page
- Response.Buffer=true
- Response.Expires=-1
- 'Show message function init()
- Functioninit()
- entryForm()
- 'Define local variables
- DimobjXML
- DimarrNames
- DimarrEmails
- DimarrURLS
- DimarrMessages
- 'Create XMLDOM document object to store messages
- SetobjXML=server.createObject(Msxml2.DOMDocument)
- objXML.async=false
- objXML.load(server.MapPath(guestbook.xml))
- 'Get a collection of elements of the message book
- SetarrNames=objXML.getElementsByTagName(name of the commentator)
- SetarrEmails=objXML.getElementsByTagName(email)
- SetarrURLS=objXML.getElementsByTagName(website)
- SetarrMessages=objXML.getElementsByTagName(Message content)
- Response.Write<tableborder='0'width='100%'>
- Response.Write<tr><tdbgcolor='#00CCFF'align='center'height='26'>
- Response.Write<b>Doctors' comments are as follows:</b>
- Response.Write</td></tr>
- 'Output content of each element of the message book, the latest message will be displayed first
- Forx=arrNames.length-1To0Step-1
- Response.Write<tr><td><ahref=mailto:&arrEmails.item(x).text&>&arrNames.item(x).text&</a></td></tr>
- Response.Write<tr><td>Website: <ahref=&arrURLS.item(x).text&target='_blank'>&arrURLS.item(x).text&</a><td></tr>
- Response.Write<tr><td>Message content:</td></tr>
- Response.Write<tr><tdbgcolor='#0099ff'>&arrMessages.item(x).text&</td></tr>
- Response.Write<tr><td></td></tr>
- Next
- Response.Write</table>
- SetobjXML=nothing
- EndFunction
- 'The function to add message record to the XML file addEntry()
- FunctionaddEntry()
- 'Define local variables
- DimstrName
- DimstrEmail
- DimstrURL
- DimstrMessage
- 'Get input content of the message form
- strName=Request.Form(name)
- strEmail=Request.Form(email)
- strURL=Request.Form(website)
- strMessage=Request.Form(Leave a message)
- DimobjXML
- DimobjEntry
- DimobjName
- DimobjEmail
- DimobjURL
- DimobjMessage
- 'Add message content to XML file
- SetobjXML=server.createObject(Msxml2.DOMDocument)
- objXML.async=false
- objXML.load(server.MapPath(guestbook.xml))
- SetobjEntry=objXML.createNode(element, message record,)
- objXML.documentElement.appendChild(objEntry)
- SetobjName=objXML.createNode(element, name of the commentator,)
- objEntry.appendChild(objName)
- objName.text=strName
- SetobjEmail=objXML.createNode(element,email,)
- objEntry.appendChild(objEmail)
- objEmail.text=strEmail
- SetobjURL=objXML.createNode(element, URL,)
- objEntry.appendChild(objURL)
- objURL.text=strURL
- SetobjMessage=objXML.createNode(element, message content,)
- objEntry.appendChild(objMessage)
- objMessage.text=strMessage
- objXML.save(server.MapPath(guestbook.xml))
- Response.Redirect(guestbook.asp)
- Endfunction
- 'Fill in and send message form function entryForm()
- FunctionentryForm()
- Response.Write<palign='center'><b>XML message book example</b></p>
- Response.Write<hrcolor='#000099'width='100%'noshade>
- Response.Write<formaction=guestbook.asp?action=addEntrymethod=post>
- Response.Write<tableborder=1>
- Response.Write<tr><td>Your name:</td><td><inputtype=textname=name/></td></tr>
- Response.Write<tr><td>Email:</td><td><inputtype=textname=email/></td></tr>
- Response.Write<tr><td>Your URL:</td><td><inputtype=textname=website/></td></tr>
- Response.Write<tr><td>Your message:</td><td><textarename=Message cols=40rows=5></textare></td></tr>
- Response.Write<tr><td></td><td><inputtype=submitvalue=post message/</td></tr>
- Response.Write</table>
- Response.Write</form>
- EndFunction
- %>
- <html>
- <head>
- <title>XML message example</title>
- <metahttp-equiv=Content-Typecontent=text/html;charset=gb2312>
- </head>
- <body>
- <%
- 'Judge whether a message has been sent and update the message information
- Dima
- a=Request.Querystring(action)
- Ifa<>Then
- addEntry
- else
- init
- EndIf
- %>
- </body>
- </html>
The above is a simple example of using XML to develop message boards, and more functions can be added as needed.