Use Asp+xml to create message book-2

Source: Internet
Author: User
Tags chr
Asp+|xml use Asp+xml to create a message book-2
(01-6-6 17)


V. Create ASP files to display XML data (index.asp)

The function of this file is to read and display the XML data, first create an XML image and then read the XML into memory, and use DOM to isolate the
The data you want.

<%
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.FreeThreadedXMLDOM")
' Create an XML pair as a free thread
Objxml.load (strsourcefile) ' reads the XML file into memory
Set objrootsite = ObjXML.documentElement.selectSingleNode ("NewList")
' Select the NewList node
%>
<title> Message Book </title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<style type= "Text/css"
!--
TD {Font-family: "Song body"; font-size:9pt; Text-decoration:none}
A {font-family: "Song body"; Font-size:9pt color: #0066CC; Text-decoration:none}
a:hover {color: #FF6600; Text-decoration:underline}
-->
</style>
<table width= "80%" border= "0" cellspacing= "1" cellpadding= "4" align= "center" bgcolor= "#CCCCCC"
<TR bgcolor= "#000000" >
<TD colspan= "2" ><font color= "#FFFFFF" "Yi Pu <a Href=" postnew.asp "><font color= #FFFFFF > > write a new message
</font> </a> </font> </td>
</tr>
<%
PageSize = 10 ' Suppose each page shows 10 messages
Allnodesnum =objrootsite.childnodes.length-1
' Get the child node data (since the maximum number of child nodes from the number of nodes is 0 minus 1)
Pagenum=allnodesnum\pagesize+1 ' Calculate the total number of pages
Pageno=request.querystring ("PageNo")
If pageno= "then" if it is every time you get the page, navigate to each page to display the latest message
Pageno=pagenum
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

'*****************************************************************************
' This makes the DOM of XML read the data, and obviously the corresponding node of the objrootsite image is <NewList>
The node for ' ObjRootsite.childNodes.item (starnodes) is the <list> node because it is not a <list> node, so the item is used ()
To identify the current node data, and as the starnodes decrements the <list> node roots up one by one to read <list> node data.
' ObjRootsite.childNodes.item (starnodes). Childnodes.item (1). text corresponds to the node as a concrete value for each node, here
(1) The corresponding is the username user name (because the <list> node's child node is what we really want)
'******************************************************************************

Text = replace (TEXT,CHR (), "<br>")
' Instead of carriage return
Text = replace (TEXT,CHR (32), "")
' Alternate spaces
%>
<TR bgcolor= "#F0F0F0" >
<TD width= "21%" height= "valign=" "Top" > name: <%=username%> <br>
From: <%=fromwhere%> <br>
</td>
<TD width= "79%" height= "valign=" "Top" | <a Href= "<%=homepage%> target=_blank title=" <%=username%
> homepage "> home page </a>
| | <a Href= "mailto: <%=email%> title=" to <%=username%> letter "> box </a> | |<font color=" #CC6633 ">
Message time: <%=Posttime%> </font> |
<%=text%> </td>
</tr>
<TR bgcolor= "#FFFFFF" align= "right"
<TD colspan= "2" > </td>
</tr>
<%
Starnodes=starnodes-1
Wend
Set objxml=nothing
%>
<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>



Related Article

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.