Tutorials to .com

Tutorials to .com » Asp » Xml » The third way to the ASP --- XML-based message board

The third way to the ASP --- XML-based message board

Print View , by: iSee ,Total views: 89 ,Word Count: 4015 ,Date: Wed, 22 Apr 2009 Time: 5:48 AM

Frankly speaking, the asp is not how I have been interested. If you want me to write this server-side procedures, then
I would choose JSP. Therefore, I always want to point at the line of the jsp cheapspace; But as miles
Predecessors have said, even are not your point, not to mention the cheapest. No alternative but to use ASP, and
For ASP message board to write the main channels, as long as they are on the Earth all know that the most used on the
Document components and database components; and most of the service providers to provide ASP-based document security disable components,
Disable some components of the database. Of course, even if few of these two components, but also does not mean we can not
Script can be used to create documents and modify the file, and we still have a third way: MSXML components.

I used the MSXML The following is a component of a message written in this process, the main document guest.xml, guest.asp,
include.asp, certain.asp, plus a number of image files, respectively, 1.jpg, 2.jpg, ... ... image
Directory file on the pic. The script in the ASP version of the test have passed, the following is the source of all
Code and on, willing to please correct me.

-------------------------------------------------- --------------------
◆ 1 ◆ guest.xml message of the document used to save the data file, which is equivalent to the database.
-------------------------------------------------- --------------------
<? xml version = "1.0" encoding = "gb2312"?>
<this message>
<Message>
<Nickname></ nickname>
<Head> pic/20.jpg </ head>
<From> Hubei Jingmen </ from>
<Time> 2002-10-17 22:48:01 </ time>
<Box> ask10@msn.com </ mail>
<Content> This is an XML-based message of the </ content>
</ Message>
<Message>
<Nickname> Juan </ name>
<Head> pic/7.jpg </ head>
<From> Wuhan </ from>
<Time> 2002-10-17 22:48:01 </ time>
<Box> fengzhongluwei@hotmail.com </ mail>
<Contents> How are you? </ Content>
</ Message>
</message this>
-------------------------------------------------- -----------------------
xml document above two messages, you can use any text editor tool for editing, if there is no syntax error,
In a browser, type the file name to display the xml tree unique to the page. Because it is a form of text, so
From the modify than to create a dedicated database to facilitate. XML documents and rules and format is also very free, if
You have to create a new XML file, simply do not change the word to write according to the first line "<? Xml version =" 1.0 "
encoding = "gb2312 "?>", label with the following text between the tags can be very random, just to comply with
To the following rules:

1. The first label and the label must correspond to the end, you can repeat, but can not be nested.
2. Label naming rules and java / c / C++ + + programming language, such as variable naming convention is similar to case-sensitive.
3. A document there can be only one root element, such as the example of the "<this message>"
4. The only keyword "XML", labels can not be at the beginning of the three letters.

If the document there is a conflict with the rules, will lead the system XML document in a browser can not display properly, and when the ASP script transfer
The document will be used when an error, it is strongly recommended that XML documents will be written first preview in a browser, there is no
Errors found, and then started working on the ASP script.

The following is on the ASP to read and write XML documents in the relevant statements: (to the top of the XML document as an example)

application components, read into the document:
set guestXml = Server.CreateObject ( "MSXML.DOMDocument")
guestXml.load Server.MapPath ( "guest.xml")

The first message shows the ""
<% = GuestXml.documentelement.childNodes.item (0). ChildNodes.item (0). Text%>
Can be interpreted as: XML object. XML root tag. Sub-tab collection. First. Sub-tab collection. First. Text
In this way, through a visit to an ultimate position in the third-level labels.
Of course, we can first set root = guestXml.documentelement.childNodes
In this way, when we want to show "" time, you can use:
<% = Root.item (0). ChildNodes.item (0). Text%>

The second message shows that the "Wuhan"
<% = GuestXml.documentelement.childNodes.item (1). ChildNodes.item (2). Text%>
And an array of similar, XML of the subscript is to start from 0.

Display a label in the number of all sub-labels, such as the total number of display messages:
<% = GuestXml.documentelement.childNodes.length%>

The first message shows the number of items in:
<% = GuestXml.documentelement.childNodes.item (0). ChildNodes.length%>

The revised document, save XML files, the changes to take effect:
<% GuestXml.save%>

In the first message to add a sub-label "<theme> a test </ theme>"
<%
set titleTag = guestXml.createelement ( "themes") to create a''label''
titleTag.text = "a test"''''' set of text labels
guestXml.documentelement.childNodes.item (1). appendchild titleTag
Added to the designated''''' tab
guestXml.save
%>
Guest.xml When you open the document again, you will find that has been successfully added.

MSXML objects is not the only grammar, but with these few key has been enough for us to write a message in this.

-------------------------------------------------- ------------------------
◆ 2 ◆ guest.asp message of the document to the home page of the face, including the total number of messages displayed and the total number of pages
-------------------------------------------------- ------------------------
<% @ LANGUAGE = "VBSCRIPT" CODEPAGE = "936"%>
<% 'So that every time the browser loading the page from the server
Response.Expires = -1
Response.AddHeader "Pragma", "no-cache"
Response.AddHeader "cache-control", "no-store"
%>
<html>
<head>
<meta name="GENERATOR" content="Microsoft frontpage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<! --
A: link (text-decoration: none; color: # 000000)
A: active (TEXT-DECORATION: none; color: # CC33FF)
A: visited (TEXT-DECORATION: none; color: # 000000)
A: hover (TEXT-DECORATION: underline overline; color: # CCCCFF)
p, br, body, td, select, input, form, textarea, option (font-family: bold; font-size: 9pt)
. input1 (font-size: 9pt; height: 18px; border: 1px # 000000 solid; background-color: # CCCCFF)
. input2 (font-size: 9pt; height: 16px; border: 1px # 000000 solid; background-color: # CCCCFF)
--></ style>
<title> 【】message I would like to use the message board dedicated to WISHES </ title>
</ head>
<body bgcolor="#cc33ff">
<center>
<table border="1" cellpadding="0" cellspacing="0" style="BORDER-COLLAPSE: collapse" bordercolor="#111111" width="750" id="AutoNumber3" height="45">
<tr>
<td width="100%" bgcolor="#9933ff" align="middle" height="21" colspan="2" style="FONT-SIZE: 9pt; FONT-FAMILY:"> 【
Message this】 </ td>
</ tr>
<%''''' Data file to open test.xml
set guestXml = Server.CreateObject ( "MSXML.DOMDocument")
guestXml.load Server.MapPath ( "guest.xml")
set root = guestXml.documentelement.childNodes

num = root.length''''' was the total number of messages
%>
<tr>
<td width="77%" bgcolor="#9933ff" align="left" height="21" style="FONT-SIZE: 9pt; FONT-FAMILY:">
<%
for i = 1 to (num-1) \ 5 +1''''' as 5 per message for one, so that the total number of pages (num-1) \ 5 +1
Response.Write ( "<a href=include.asp?page="& i &" target=include>")
Response.Write ( "No." & i & "page |")''''' through this cycle it has developed a navigation between pages.
Response.Write ( "</ a>")''''' equivalent HTML code <a href=include.asp?page=1 target=include> Page 1 </ a>
next
%>
</ td>
<td width="23%" bgcolor="#9933ff" align="middle" height="21" style="FONT-SIZE: 9pt; FONT-FAMILY:"> <A href = "piclist. html "target =" _blank "> head of the list </ A>
| <label Id=lab1 onclick="window.scroll(0,70)"> to write messages </ label> </ td>
</ tr>
</ table>
<p> <iframe name = "include" width = "749" height = "314" src = "include.asp" style = "BORDER-RIGHT: # 000000 1px double; PADDING-RIGHT: 4px; BORDER-TOP: # 000000 1px double; PADDING-LEFT: 4px; PADDING-BOTTOM: 1px; BORDER-LEFT: # 000000 1px double; PADDING-TOP: 1px; BORDER-BOTTOM: # 000000 1px double ">
Browser does not support the embedded frame, or configured to not display the embedded framework. </ iframe> </ p>
<table border = "1" cellpadding = "0" cellspacing = "0" bgcolor = "# 9933ff" style = "BORDER-COLLAPSE: collapse" bordercolor = "# 111111" width = "750" id = "AutoNumber4" height = "1">
<form method="POST" action="certain.asp">
<tr>
<td width="21" height="1" align="left" style="VERTICAL-ALIGN: middle; LINE-HEIGHT: 150%; LETTER-SPACING: 3pt" rowspan="3"> gift message language </ td>
<td width="96" height="25" align="middle"> your name: </ td>
<td width="171" height="25" align="middle">
<INPUT Size="20" name="textname" class="input1">
</ td>
<td width="88" height="25" align="middle"> where you: </ td>
<td width="194" height="25" align="middle">
<INPUT Size="20" name="textadd" class="input1">
</ td>
<td width="173" height="25" align="middle" colspan="2">
<INPUT Size="20" name="textmail" value="yourmail@" class="input1">
</ td>
</ tr>
<tr>
<td width = "552" height = "1" colspan = "4" rowspan = "2"
align = "center">
<TEXTAREA style = "border-style: double; border-width: 3; WIDTH: 523px; HEIGHT: 37px; background-color: # CCCCFF; overflow: hidden" cols = "72" rows = "1" name = "textmsg "class =" input1 ">
</ TEXTAREA> </ td>
<td width="10" height="1" rowspan="2" align="center"> <img border = "0" src = "pic/1.jpg" width = "40" height = "56" id = idface>
</ td>
<td width="159" height="1" align="center"> <SELECT name = "list" class = "input1" style = "WIDTH: 61; height: 61" onchange = "document.images [ 'idface']. src = options [selectedIndex]. value; ">
<option value=pic/1.jpg selected> Head 1
<script language=vbscript>
for i = 2 to 15''''' cycle, the drop-down list to set up the other 14 documents
document.write ( "<option value=pic/"&i&".jpg> Head" & i)
next
</ script>
</ option>
</ SELECT>
<INPUT Style="WIDTH: 65px; HEIGHT: 19px" type="button" value="" class="input2">
</ td>
</ tr>
<tr>
<td width="159" height="1" align="center"> <INPUT style = "WIDTH: 65px; HEIGHT: 19px" type = "reset" size = "25" value = "empty" class = " input2 ">
<INPUT Style="WIDTH: 65px; HEIGHT: 19px" type="submit" value="" class="input2"> </ td>
</ tr>
</ form>
</ table>
</ center>

<%''''' In the browser's status bar shows such as "the current total of 8 messages, two points indicate that the recent messages are Mr Chan"
status = "current total" & num & "message, sub" & (num-1) \ 5 +1 & "page, the latest message is" & guestXml.documentelement.lastchild.firstchild.text
Response.Write ( "<script>")
Response.Write ( "window.status =" & chr (34) & status & chr (34))
Response.Write ( "</ script>")
%>

</ body>
</ html>

-------------------------------------------------- ----------------------------
◆ 3 ◆ include.asp the document embedded in the page, the message to display.
-------------------------------------------------- ----------------------------

<% 'So that every time the browser loading the content from the server
Response.Expires = -1
Response.AddHeader "Pragma", "no-cache"
Response.AddHeader "cache-control", "no-store"
%>

<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
Message presented <title> language </ title>
<style>
<! --
p, br, body, td, select, input, form, textarea, option (font-family: bold; font-size: 9pt)
table (border-style: double; border-width: 3; padding: 0; border-collapse: collapse)
. input1 (font-size: 9pt; border: 1px # 000000 solid; background-color: # CCCCFF)

->
</ style>
</ head>

<body bgcolor="#CC33FF">
<center>

<%''''' Message of this data file open
set guestXml = Server.CreateObject ( "MSXML.DOMDocument")
guestXml.load (Server.MapPath ( "guest.xml"))
set root = guestXml.documentelement
num = root.childNodes.length

page = Request.QueryString ( "page")
if page = Empty then''''' If there is no parameter, that is, http:// ... / include.asp the circumstances.
thispage = (num-1) \ 5 +1''''' Message 5 per page, with thispage that the current page, without parameters to display the last page of transmission.
if num mod 5 = 0 then
msgTotal = 5''''' variable msgTotal that should show the current page number of the message
else
msgTotal = num mod 5
end if
else
thispage = page''''' similar to http:// ... / include.asp? page = 1 when the situation
if StrComp (thispage, (num-1) \ 5 +1,1) = 0 then
msgTotal = num mod 5
else
msgTotal = 5
end if
end if
msgNum = (thisPage-1) * 5 + msgTotal''''msgNum that page shows the current message is the total number of the first section of Article N
''''Because it is displayed in reverse order, so the first message should be (thisPage-1) * 5 + msgTotal
%>

<% For i = 1 to msgTotal%>
<%
set xmlNode = root.childNodes.item (msgNum-1). childNodes''target of the message to read
name = xmlNode.item (0). text''''' name that the message variable's name.
pic = xmlNode.item (1). text''''' pic head variables that address.
add = xmlNode.item (2). text''''' add message variables that person's address.
thistime = xmlNode.item (3). text''''' this variable indicated that the time messages.
Message''who''do not show the EMAIL.
msg = xmlNode.item (5). text''''msg message that the contents of variables.
%>
<table border="1" cellpadding="0" cellspacing="0" bordercolor="#111111" width="100%" height="106" bgcolor="#FFFFFF">
<tr>
<td width="14%" rowspan="3" height="106" align="center">
<img border = "0"
src = <% = pic%> width = "100" height = "143"> </ td>
<td width="9%" height="10" align="center" bgcolor="#99CCFF"> Name </ td>
<td width="31%" height="10" align="center" bgcolor="#CCCCFF"> <% = name%> </ td>
<td width="10%" height="10" align="center" bgcolor="#99CCFF"> from </ td>
<td width="36%" height="10" align="center" bgcolor="#CCCCFF"> <% = add%> </ td>
</ tr>
<tr>
<td width = "86%" height = "83" colspan = "4" align = "center"
bgcolor = "# 9933FF"
style = "line-height: 150%; margin-left: 50; margin-right: 50">
<TEXTAREA Name="textmsg" class="input1" rows="6" cols="87" readonly> <% = msg%> </ TEXTAREA> </ td>
</ tr>
<tr>
<td width="86%" height="11" colspan="4" align=right bgcolor="#CCCCFF"> the first <% = thispage%> Page | section <% = msgTotal-i +1%> Article | <% = thistime%> | </ td>
</ tr>
</ table>
<br>
<%
msgNum = msgNum-1''''show in reverse order, so the next message should be the subscript is subscript -1
next''''cycle.
%>
</ center>
</ body>
</ html>

-------------------------------------------------- -----------------------
◆ 4 ◆ certain.asp for the document to the XML file to add records, and confirm message.
-------------------------------------------------- -----------------------
<html>

<head>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv = "Content-Type" content = "text / html;

charset = gb2312 ">
<title> 【Guestbook】the confirmation message </ title>
</ head>
<script language=vbscript>
sub btn1_onclick''''' when pressing the "View Message", it will lead to a message page page
window.location = "guest.asp"
end sub

sub btn2_onclick
window.close
end sub
</ script>

<body>

<% 'Define a function, for the seizure of the contents of messages.
function htmlencode (str)
dim result
dim l
if isNULL (str) then
htmlencode = ""
exit function
end if
l = len (str)
result = ""
dim i
for i = 1 to l
select case mid (str, i, 1)
case "<"
result = result + "<"
case ">"
result = result + ">"
case else
result = result + mid (str, i, 1)
end select
next
htmlencode = result
end function

set guestXml = Server.CreateObject ( "MSXML.DOMDocument")
guestXml.load (Server.MapPath ( "guest.xml"))
set root = guestXml.documentelement

name = Request.Form ( "textname")''''' seized the submission form.
pic = Request.Form ( "list")
add = Request.Form ( "textadd")
email = Request.Form ( "textmail")
thistime = now ()
msg = Request.Form ( "textmsg")

set newTag = guestXml.createelement ( "Message")
root.appendchild newTag

set currentTag = root.lastChild

set nameTag = guestXml.createelement ( "Name")
nameTag.text = htmlencode (name)
currentTag.appendchild nameTag

set picTag = guestXml.createelement ( "Head")
picTag.text = pic
currentTag.appendchild picTag

set addTag = guestXml.createelement ( "from")
addTag.text = htmlencode (add)
currentTag.appendchild addTag

set timeTag = guestXml.createelement ( "time")
timeTag.text = thistime
currentTag.appendchild timeTag

set emailTag = guestXml.createelement ( "Box")
emailTag.text = htmlencode (email)
currentTag.appendchild emailTag

set msgTag = guestXml.createelement ( "Content")
msgTag.text = htmlencode (msg)
currentTag.appendchild msgTag

guestXml.save (Server.MapPath ( "guest.xml"))
%>
<embed width="350" height="200" src="pic/certain.swf" style="position: absolute; left: 214; top: 86">''''' a flash file.
<input type = "button" value = "View Message" name = "btn1"
style = "position: absolute; left: 282; top: 313; border-style: solid; border-width: 1; background-color: # ABB52F">
<input type = "button" value = "Close this page" name = "btn2"
style = "position: absolute; left: 414; top: 313; border-style: solid; border-width: 1; background-color: # ABB52F">
</ body>
</ html>

-------------------------------------------------- -------------------------------
Remarks:

Since we are using XML file data, add data in the HTML filter is very important. Database-based
Guestbook accidentally left in a HTML tag may not pose any major problems, but in XML, the result is a serious
Just a marker, or even just a "<" can make your message the paralysis.
Such as "<name> John <out strong </ name>" ... ... ... ... ... ... ... ... ...

Above four documents have been tested source code, copy to use later.
If you want to see examples demonstrate, you can click the link behind the sample

You can also http://0724.y365.com/guest.rar Department from
Download all the script file with the image file compression packages.

To investigate if there is any mistakes, please correct me and discussed.

Miles these days thanks to head to the tireless help, no to return, this article only on the shrub.


Asp and XML related Articles


Can't Find What You're Looking For?


Rating: 0.0

Comments

No comments posted.