欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Asp 解析 XML并分页显示源码

程序员文章站 2022-08-10 17:54:38
asp 解析 xml并分页显示,示例源码如下: 复制代码 代码如下:
asp 解析 xml并分页显示,示例源码如下:
复制代码 代码如下:

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link href="http://www.fx678.com/css/cur_topics.css" rel="stylesheet" type="text/css" />
<script language="javascript" type="text/ecmascript" src="http://www.fx678.com/js/jquery-1.8.0.min.js"></script>
<title>财富动力专题</title>
<style type="text/css">
#right_topic
{
float: right;
height: auto;
width: 690px;
}
#right_topic .xinhua
{
clear: both;
width: 690px;
overflow: hidden;
font-size: 14px;
color: #444;
line-height: 24px;
}
#right_topic .xinhua img
{
border: 0;
}
#right_topic .xinhua .top_cont
{
border: 1px solid #ddd;
height: 140px;
}
#right_topic .xinhua .top_cont .xh_logo
{
width: 270px;
float: left;
margin: 25px 10px;
}
#right_topic .xinhua .top_cont .xh_text
{
float: right;
width: 390px;
font-size: 14px;
line-height: 22px;
color: #666;
margin-top: 15px;
}
.list
{
clear: both;
margin-top: 15px;
overflow: hidden;
border-bottom: 3px solid #206295;
}
.list ul
{
margin: 0;
padding: 0;
}
.list ul li
{
list-style: none;
border-bottom: 1px dotted #e5e5e5;
padding: 10px;
}
.list ul li h4
{
font-family: "microsoft yahei";
font-size: 18px;
font-weight: normal;
line-height: 22px;
margin: 0px;
margin-bottom: 5px;
padding: 0;
color: #0761b7;
}
.list ul li h4 a
{
color: #206295;
text-decoration: none;
}
.list ul li h4 a:hover
{
text-decoration: underline;
}
.list ul li span
{
float: right;
width: 120px;
color: #999;
font-size: 14px;
text-align: right;
}
.list ul li p
{
margin: 0;
padding: 0;
font-size: 12px;
}
.list ul li.bg
{
background: #f5f8fa;
}
#pagezone
{
background: #f5f6fb;
border-bottom: 1px solid #dbe3ee;
margin: 10px auto 20px;
padding: 10px 0;
text-align: center;
}
#pagezone span
{
background: #ffffff;
border: 1px solid #d8dadf;
font-size: 14px;
height: 34px;
line-height: 34px;
margin: 0px 2px;
padding: 8px 12px;
}
#pagezone span a
{
color: #666;
text-decoration: none;
}
#pagezone span.isnow
{
background: #206295;
border: 1px solid #d8dadf;
color: #ffffff;
}
</style>
<script type="text/javascript">
var $m = $(window.parent.document).find("#myxh08");
$m.load(function () {
var thish = $(document).height() + 30;
$m.height(thish);
});
</script>
</head>
<body style="width: 690px;">
<!-- 列表信息 -->
<div class="list">
<ul>
<%
dim xmldoc,objnodes,pindex,psize,i,http,xmlurl
psize = 10 '页大小
xmlurl ="http://back.moneypower.cn/news.xml"

rem 页索引
pindex = request.querystring("p")
if cint(pindex) > 6 or cint(pindex) < 1 then
pindex = 1
end if

rem 异步读取xml源
set http = server.createobject("microsoft.xmlhttp")
http.open "get",xmlurl,false
http.send

rem 定义 读取xml 的变量
set xmldoc = server.createobject("microsoft.xmldom")
xmldoc.async = false
xmldoc.validateonparse = false
xmldoc.load(http.responsexml)

set objnodes = xmldoc.getelementsbytagname("item")

if objnodes.length > 0 then
i = 0
for j = (psize*(pindex-1)) to (psize*pindex-1) step 1
mytitle = objnodes(j).childnodes(0).text
mydate = objnodes(j).childnodes(3).text
mydescription = objnodes(j).childnodes(2).text
link = server.urlencode(objnodes(j).childnodes(1).text)
mylink = "http://www.fx678.com/news/currency/xh08newscontent.asp?u=" & link
%>
<% if i mod 2 = 0 then %>
<li class="bg">
<% else %>
<li>
<% end if %>
<h4>
<span>
<%= formatdate(mydate,2) %>
</span><a target="_blank" href="<%= mylink %>">
<%= mytitle %></a></h4>
<p>
<%= mydescription %>
</p>
</li>
<%
i = i + 1
next
else
response.write("暂无数据!")
end if
%>
</ul>
</div>
<!-- 分页信息 -->
<div id="pagezone">
<%
if pindex = 1 then
%>
<span class="disabled">第一页</span>
<span class="disabled"><<上一页</span>
<span class="isnow number" title="您正在浏览本页">1</span>
<span class="number" title="第2页">
<a href="zt_cfdl_list.asp?p=2">2</a>
</span>
<span class="number" title="第3页">
<a href="zt_cfdl_list.asp?p=3">3</a>
</span>
<span class="number" title="第4页">
<a href="zt_cfdl_list.asp?p=4">4</a>
</span>
<span class="number" title="第5页">
<a href="zt_cfdl_list.asp?p=5">5</a>
</span>
<span class="number" title="第6页">
<a href="zt_cfdl_list.asp?p=6">6</a>
</span>
<span title="转到下一页">
<a href="zt_cfdl_list.asp?p=<%= cint(pindex+1) %>">下一页>></a>
</span>
<span title="转到最后一页">
<a href="zt_cfdl_list.asp?p=6">最后一页</a>
</span>
<%
elseif pindex = 6 then
%>
<span class="disabled">
<a href="zt_cfdl_list.asp?p=1">第一页</a>
</span>
<span title="转到上一页">
<a href="zt_cfdl_list.asp?p=<%= cint(pindex-1) %>">上一页</a>
</span>
<span class="number" title="第1页">
<a href="zt_cfdl_list.asp?p=1">1</a>
</span>
<span class="number" title="第2页">
<a href="zt_cfdl_list.asp?p=2">2</a>
</span>
<span class="number" title="第3页">
<a href="zt_cfdl_list.asp?p=3">3</a>
</span>
<span class="number" title="第4页">
<a href="zt_cfdl_list.asp?p=4">4</a>
</span>
<span class="number" title="第5页">
<a href="zt_cfdl_list.asp?p=5">5</a>
</span>
<span class="number isnow" title="您正在浏览本页">6</span>
<span class="disabled">下一页>></span>
<span class="disabled" title="转到最后一页">最后一页</span>
<%
else
%>
<span class="number">
<a href="zt_cfdl_list.asp?p=1">第一页</a>
</span>
<span title="转到上一页">
<a href="zt_cfdl_list.asp?p=<%= cint(pindex-1) %>">上一页</a>
</span>
<%
for m = 1 to 6 step 1
if cint(pindex) = cint(m) then
%>
<span class="number isnow" title="您正在浏览本页"><%= m %></span>
<%
else
%>
<span class="number" title="第<%= m %>页">
<a href="zt_cfdl_list.asp?p=<%= m %>"><%= m %></a>
</span>
<%
end if
next
%>
<span title="转到下一页">
<a href="zt_cfdl_list.asp?p=<%= cint(pindex+1) %>">下一页>></a>
</span>
<span title="转到最后一页">
<a href="zt_cfdl_list.asp?p=6">最后一页</a>
</span>
<%
end if
%>
</div>
</body>
</html>

<%
public function formatdate(dateandtime, para)
on error resume next
dim y, m, d, h, mi, s, strdatetime
formatdate = dateandtime
if not isnumeric(para) then exit function
if not isdate(dateandtime) then exit function
y = cstr(year(dateandtime))
m = cstr(month(dateandtime))
if len(m) = 1 then m = "0" & m
d = cstr(day(dateandtime))
if len(d) = 1 then d = "0" & d
h = cstr(hour(dateandtime))
if len(h) = 1 then h = "0" & h
mi = cstr(minute(dateandtime))
if len(mi) = 1 then mi = "0" & mi
s = cstr(second(dateandtime))
if len(s) = 1 then s = "0" & s
select case para
case "1"
strdatetime = y & "-" & m & "-" & d & " " & h & ":" & mi & ":" & s
case "2"
strdatetime = y & "-" & m & "-" & d
case "3"
strdatetime = y & "/" & m & "/" & d
case "4"
strdatetime = y & "年" & m & "月" & d & "日"
case "5"
strdatetime = m & "-" & d
case "6"
strdatetime = m & "/" & d
case "7"
strdatetime = m & "月" & d & "日"
case "8"
strdatetime = y & "年" & m & "月"
case "9"
strdatetime = y & "-" & m
case "10"
strdatetime = y & "/" & m
case "11"
strdatetime = m & "-" & d & " " & h & ":" & mi
case "12"
strdatetime = h & ":" & mi & ":" & s
case "13"
strdatetime = y & m & d & h & mi & s
case "14"
strdatetime = y & m & d
case "15"
strdatetime = h & mi & s
case "16"
strdatetime = h & ":" & mi
case "17"
strdatetime = y & m & d & h & mi & s
case "18"
strdatetime = y & m & d
case "19"
strdatetime = y & m
case else
strdatetime = dateandtime
end select
formatdate = strdatetime
end function
%>

效果图(部分):
Asp 解析 XML并分页显示源码