您现在的位置是:网站首页> 编程资料编程资料

Asp 解析 XML并分页显示源码_应用技巧_

2023-05-25 190人已围观

简介 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.fx678.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
%>

效果图(部分):

-六神源码网