热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Asp解析XML并分页显示源码

Asp解析XML并分页显示源码:Asp解析XML并分页显示,示例
Asp 解析 XML并分页显示,示例源码如下:
代码如下:




    <%
    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.gxlsystem.com/news/currency/XH08NewsContent.asp?u=" & link
    %>
    <% if i Mod 2 = 0 then %>

  • <% else %>

  • <% end if %>



    <%= FormatDate(myDate,2) %>
    ">
    <%= myTitle %>



    <%= myDescription %>



  • <%
    i = i + 1
    Next
    Else
    Response.Write("暂无数据!")
    End If
    %>


<%
if pIndex = 1 then
%>
第一页
<<上一页
1

2


3


4


5


6


">下一页>>


最后一页

<%
elseif pIndex = 6 then
%>

第一页


">上一页


1


2


3


4


5

6
下一页>>
最后一页
<%
else
%>

第一页


">上一页

<%
for m = 1 to 6 step 1
if Cint(pIndex) = Cint(m) then
%>
<%= m %>
<%
else
%>

"><%= m %>

<%
end if
next
%>

">下一页>>


最后一页

<%
end if
%>


<%
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
%> 效果图(部分):

推荐阅读
author-avatar
小二上酒
拿起键盘就是撸~~
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有