End If
Starnodes=pageno*pagesize-1 ' Get Start node
Endnodes= (PageNo-1) *pagesize ' Get End node
If Endnodes<0 Then
Endnodes=0
End If
If Starnodes>allnodesnum then ' determines whether the number of starting nodes exceeds the total number of nodes
endnodes=endnodes-(Starnodes-allnodesnum)
' If the difference between the end node minus (Starnodes-allnodesnum) is exceeded, the next rcas is out of bounds error
Starnodes=allnodesnum
End If
If Endnodes<0 Then
Endnodes=0
End If
While Starnodes>=endnodes
' Read node data from end node to super start node
Username = ObjRootsite.childNodes.item (starnodes). Childnodes.item (1). Text
' Get user name
Fromwhere = ObjRootsite.childNodes.item (starnodes). Childnodes.item (2). Text
' Get users from there
Posttime = ObjRootsite.childNodes.item (starnodes). Childnodes.item (3). Text
' Get message time
Homepage = ObjRootsite.childNodes.item (starnodes). Childnodes.item (4). Text
' Get user homepage
email = objRootsite.childNodes.item (starnodes). Childnodes.item (5). Text
' Get user Eamil
Text = ObjRootsite.childNodes.item (starnodes). Childnodes.item (6). Text
' Received yesterday's message content
The
' *****************************************************************************
' here makes the DOM of XML read the data, It is obvious that the corresponding node of the objrootsite is <newlist>, and that the
' ObjRootsite.childNodes.item (starnodes) corresponds to the node is <list> node because less than one <list> node Therefore, the item () is used to identify the current node data, and as the Starnodes <list> node roots up one by one to read the <list> node data.
' ObjRootsite.childNodes.item (starnodes). Childnodes.item (1). text corresponds to the node is specific to each node of the text value, here (1) The corresponding is the username username (because <list> node's child node is what we really want)
' ********************************************************* *********************
Text = replace (TEXT,CHR (), <br>)
Replace carriage return
Text = replace (TEXT,CHR), "")
' alternate space
' %>
<tr bgcolor= "#F0F0F0" >
<td width= "21%" height= "the" valign= "Top" > Name:<%=username%>< Br>
From: <%=fromwhere%><br>
</td>
<td width= "79%" height= "the" valign= "Top" > | A href= "<%=homepage%>" Target=_blank title= "<%=username%
> Home" > Home </a>
| | <a href= "mailto:<%=email% > "title=" to <%=username%> writing "> Mailbox </a> | |< Font color= "#CC6633" >
Message Time:<%=posttime%> </font>|
<%=text%> </td>
</tr>
<tr bgcolor= "#FFFFFF" align= "right"
&L T;TD colspan= "2" > </td>
</tr>
<%
starnodes=starnodes-1
Wend
Set Objxml=nothin G
%>
<tr bgcolor= "#FFFFFF" align= "right" >
<TD colspan= "2" > Total <<%=PageNum%>> page
<%
If CInt (pageno) <>pagenum Then ' paging
Response.Write "<a href= ' index.asp?" Pageno= "& (pageno+1) &" ' > Prev </a> "
End If
If CInt (pageno) <>1 Then
Response.Write "<a href= ' index.asp?" Pageno= "& (PageNo-1) &" ' > Next page </a> "
End If
%>
</td>
</tr>
</table>
</body>
Vi. establishment of a new message program (postnew.asp)
The function of this file is to write a new XML node, first create an XML image and then read the XML into memory, and join our generated XML node with the AppendChild () method.
<%
Username=request.form ("username")
If username<> "" Then
Fromwhere =request.form ("Fromwhere")
Homepage =request.form ("homepage")
Email =request.form ("email")
Text =request.form ("text")
Text =replace (text, "<", "<")
Posttime =now ()
strSourceFile = Server.MapPath ("/") & "\list.xml"
' Get the path to the XML file, which is different depending on your virtual directory.
Set objxml = Server.CreateObject ("Microsoft.XMLDOM")
' Create an XML pair like
Objxml.load (strSourceFile)
' Read the XML file into memory
Set objrootlist = ObjXML.documentElement.selectSingleNode ("NewList")
' Select <NewList> node
If Objrootlist.haschildnodes Then
' Determine whether <NewList> has child nodes (because if each <NewList> is not a child node,
' If you don't make a judgment, you'll get an error at the first time.
id = objrootlist.lastchild.firstchild.text+1
' Here gets the ID number of the child node that will be inserted, with the ID number of the first child node (firstchild) of the last child node of <NewList> (LastChild) plus 1 (here we increment according to the ID number of the relational database)
Else
' If no word child node is the first time message ID number set to 1
Id=1
End If
BRSTR=CHR (&CHR) &CHR (9)
' To insert the nodes in the XML file to line up lines of space
' (Of course you can not do this just for the sake of XML data.)
xmlnode=brstr& "<list>" &brstr & _
"<id>" &id& "</id>" &brstr & _
"<username>" &username& "</username>" &brstr & _
"<fromwhere>" &fromwhere& "</fromwhere>" &brstr & _
"<Posttime>" &Posttime& "</Posttime>" &brstr & _
""<email>" &email& "</email>" &brstr & _
"<text>" &text& "</text>" &brstr & _
"</list>" &CHR (13)
' Create an XML fragment based on the resulting data
Set Objxml2=server.createobject ("Microsoft.XMLDOM")
' Create a new XML pair like
Objxml2.loadxml (XMLnode)
' Read the XML fragment into memory
Set Rootnewnode=objxml2.documentelement
' Get the root node of objXML2
Objrootlist.appendchild (Rootnewnode)
' Insert the XML fragment into the List.xml
Objxml.save (strSourceFile)
' Store Lsit.xml file (because no storage list.xml is updated in memory only)
Set objxml=nothing
Set objxml2=nothing
Response.Write "Thank you for your message."
Response.End
End If
%>
<title>untitled document</title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<style type= "Text/css" >
<!--
td {FONT-SIZE:9PT}
-->
</style>
<body bgcolor= "#0099CC" text= "#000000" >
<table width= "80%" border= "0" cellspacing= "1" cellpadding= "4" align= "center" bgcolor= "#FFFFFF" >
<form action= "postnew.asp" method= "Post" Name= "Form1" >
<tr bgcolor= "#000000" >
<TD colspan= "2" ><font color= "#FFFFFF" > New Message </font></td>
</tr>
<tr bgcolor= "#EFEFEF" >
<TD width= "19%" align= "right" > name:</td>
<TD width= "81%" >
<input type= "text" name= "username" >
* * </td>
</tr>
<tr bgcolor= "#EFEFEF" >
<TD width= "19%" align= "right" > from:</td>
<TD width= "81%" >
<input type= "text" name= "Fromwhere" value= "China" >
</td>
</tr>
<tr bgcolor= "#EFEFEF" >
<TD width= "19%" align= "right" > home page:</td>
<TD width= "81%" >
<input type= "text" name= "homepage" value= "http://" >
</td>
</tr>
<tr bgcolor= "#EFEFEF" >
<TD width= "19%" align= "right" >Email:</td>
<TD width= "81%" >
<input type= "text" name= "email" >
</td>
</tr>
<tr bgcolor= "#EFEFEF" >
<TD width= "19%" align= "right" valign= "top" > Content:</td>
<TD width= "81%" >
<textarea name= "text" cols= "rows=" ></textarea>
</td>
</tr>
<tr bgcolor= "#EFEFEF" >
<TD width= "19%" align= "right" > </td>
<TD width= "81%" >
<input type= "Submit" name= "Submission" value= "submitted" >
<input type= "reset" name= "Submit2" value= "refill" >
</td>
</tr>
</form>
</table>
</body>
Vii. Summary
Here we'll build a simple and paging XML message book, Ah, it is easy to read, in fact, I only have a starting point of the function, the purpose is to guide you to build more complex and better asp+xml procedures, such as: The above message this plus the reply function, management function, click the data function, etc. Even you can change it into a BBS and so on. Last message the results of this operation are as follows:
(The results of the operation List.xml under IE5)
(Message this index.asp run result)
(postnew.asp results)
Finally, if you copy my above program does not run, but it is copy or I comment error (but the home page to check strsourcefile = Server.MapPath ("/") & "\list.xml" Here is wrong, But I can tell you if the hint is missing to like so many is here a mistake, finally you can go to http://Page2000.xiloo.com to download the source program, you can also write to me asp_boys@cmmail.com I will send you the source program as soon as possible. If you have any questions you can go to Http://www.4u2v.com/bbs because I'm there to answer some of the questions I know.