当前位置: 移动技术网 > IT编程>开发语言>.net > 用ASP+XML打造留言本(2)

用ASP+XML打造留言本(2)

2019年01月16日  | 移动技术网IT编程  | 我要评论

青阳论坛,卡优卡,野上彻

五、建立显示xml(标准化越来越近了)数据的asp文件(index.)

  这个文件要实现的功能就是读取并显示xml(标准化越来越近了)数据,首先创建一个xml(标准化越来越近了)对像然后把xml(标准化越来越近了)读入内存中,利用dom分离出我们所要的数据。

<%
strsourcefile = server.mappath("/") & "list.xml(标准化越来越近了)"
获取xml(标准化越来越近了)文件的路径这里根据你的虚拟目录不同而不同
set objxml(标准化越来越近了) = server.createobject("microsoft.freethreadedxml(标准化越来越近了)dom")
以自由线程创建一个xml(标准化越来越近了)对像
objxml(标准化越来越近了).load(strsourcefile)把xml(标准化越来越近了)文件读入内存
set objrootsite = objxml(标准化越来越近了).documentelement.selectsinglenode("newlist")
选取newlist节点
%>
<html>
<head>
<title>留言本</title>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
td { font-family: "宋体"; font-size: 9pt; text-decoration: none}
a { font-family: "宋体"; font-size: 9pt; color: #0066cc; text-decoration: none}
a:hover { color: #ff6600; text-decoration: underline}
-->
</style>
</head><body bgcolor="#0099cc" text="#000000">
<table width="80%" border="0" cellspacing="1" cellpadding="4" align="center" bgcolor="#cccccc">
<tr bgcolor="#000000">
<td colspan="2"><font color="#ffffff">留言溥 <a href="postnew.asp"><font color=#ffffff>写新留言</font></a></font></td>
</tr>
<%
pagesize =10假设每页显示10条留言
allnodesnum =objrootsite.childnodes.length-1
获取子节点数据(因为是从节点数从0开始的所最大子节点数要减1)
pagenum=allnodesnumpagesize+1算出总页数
pageno=request.querystring("pageno")
if pageno="" then如果是每一次获得页面则定位到每一页显示最新的留言
pageno=pagenum
end if
starnodes=pageno*pagesize-1获得起始节点
endnodes=(pageno-1)*pagesize获得结束节点
if endnodes<0 then
endnodes=0
end if
if starnodes>allnodesnum then判断起始节点数是否超过总的节点数
endnodes=endnodes-(starnodes-allnodesnum)
如果超过则结束节点要减去(starnodes-allnodesnum)的差值否则下标会超界出错
starnodes=allnodesnum
end if
if endnodes<0 then
endnodes=0
end if
while starnodes>=endnodes
从结束节点到超始节点之间读取节点数据
username = objrootsite.childnodes.item(starnodes).childnodes.item(1).text
获得用户名
fromwhere = objrootsite.childnodes.item(starnodes).childnodes.item(2).text
获得用户来自那里
posttime = objrootsite.childnodes.item(starnodes).childnodes.item(3).text
获得留言时间
homepage = objrootsite.childnodes.item(starnodes).childnodes.item(4).text
获得用户主页
email = objrootsite.childnodes.item(starnodes).childnodes.item(5).text
获得用户eamil
text = objrootsite.childnodes.item(starnodes).childnodes.item(6).text
获昨留言内容

*****************************************************************************
这里使作了xml(标准化越来越近了)的dom来读取数据,显然objrootsite对像所对应的节点为<newlist>
objrootsite.childnodes.item(starnodes)所对应的节点就是<list>节点因为不至一个<list>节点所以用了item()来识别当前节点数据,随着starnodes的递减<list>节点根着往上移一个个读取<list>节点数据。
objrootsite.childnodes.item(starnodes).childnodes.item(1).text所对应的节点为具体的每个节点的文本值,这里(1)所对应的就是username用户名(因为<list>节点的子节点才是我们真正所要的)
******************************************************************************

text = replace(text,chr(13),"<br>")
替代回车
text = replace(text,chr(32)," ")

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网