-- 作者:ajak.xml
-- 发布时间:3/29/2004 9:29:00 PM
-- xml 数据存取: xml dom & asp 初次发贴不成敬意...
<!-- '下面是一个完整的基于xml的网站统计页面 '仅供参考 . Contact me: ajak@eyou.com --> <!-- 建立 xml 文件: list.xml --> <?xml version="1.0" encoding="gb2312"?> <newlist> <list> <a>12</a> <b>21</b> <c>15</c> <d>5</d> <ip>192.168.0.1</ip> </list> </newlist> <!-- 存取 xml 文件: voting.asp --> <% strSourceFile="C:\...\list.xml" '被存取 xml 文件的绝对文件地址 Set objXML = Server.CreateObject("Microsoft.XMLDOM") '创建 xml dom objXML.load(strSourceFile) '取得 xml 文件 Set rootNode = objXML.documentElement Set objRootsite = objXML.getElementsByTagName("list") ' a=objRootsite.item(0).childnodes.item(0).text b=objRootsite.item(0).childnodes.item(1).text c=objRootsite.item(0).childnodes.item(2).text d=objRootsite.item(0).childnodes.item(3).text ip=objRootsite.item(0).childnodes.item(4).text ' %> <% Dim thisIP thisIP = Request.ServerVariables("REMOTE_ADDR") If thisIP=ip Then '限制 ip Response.Redirect("error.asp?id=001") '转向错误处理页面 Else vote = Request("vote") If vote <> Empty Then Select case vote case"va" a = a + 1 objRootsite.item(0).childnodes.item(0).text = a case"vb" b = b + 1 objRootsite.item(0).childnodes.item(1).text = b case"vc" c = c + 1 objRootsite.item(0).childnodes.item(2).text = c case"vd" d = d + 1 objRootsite.item(0).childnodes.item(3).text = d End Select objRootsite.item(0).childnodes.item(4).text = thisIP objXML.save(strSourceFile) '写入更新后的结果 Response.Redirect("../index.asp") '返回请求页面 End If End If %> <!-- 单独编写 结果显示页面的代码: display.asp --> <% strSourceFile="C:\...\list.xml" Set objXML = Server.CreateObject("Microsoft.XMLDOM") objXML.load(strSourceFile) Set rootNode = objXML.documentElement Set objRootsite = objXML.getElementsByTagName("list") a=objRootsite.item(0).childnodes.item(0).text b=objRootsite.item(0).childnodes.item(1).text c=objRootsite.item(0).childnodes.item(2).text d=objRootsite.item(0).childnodes.item(3).text %> <% Total = CInt(a) + CInt(b) + CInt(c) + CInt(d) '数据类型转换 If Total>0 Then per1 = a/Total per2 = b/Total per3 = c/Total per4 = d/Total End If %> <!-- 结果显示: vote.asp --> <!--#include file="display.asp" --> <html> <head> <title>:: Vote for my page ::</title> <style type="text/css"> <!-- td{filter:alpha(opacity=80);font-size:18pt;font-family:华文行楷;color:black;background-color:white;} a:active,a:link,a:visited{font-family:华文行楷;font-size:18pt;color:#000000;text-decoration:none;} a:hover{font-family:华文行楷;font-size:18pt;color:#ff0000;text-decoration:underline;} body{ background-image:url(../bg.jpg); background-repeat:no-repeat; filter:alpha(opacity=80); background-position:35px top; background-color:#eaebfc; font-seze:11pt; cursor:default; } --> </style> </head> <body topmargin="70" marginwidth="0" onselectstart="return false" oncontextmenu=self.event.returnValue=false> <table border="0" cellpadding="5" cellspacing="1" align="center"> <tr align="center" height="70"><td colspan="5" style="padding-top:13px;">网站投票统计表</td></tr> <tr height="220" valign="bottom"> <td valign="middle" align="center" width="110" rowspan="2">投 票 结 果</td> <td width="120" align="center"><img width="60" src="../bg.gif" height=<%= per1*400 %>></td> <td width="120" align="center"><img width="60" src="../bg.gif" height=<%= per2*400 %>></td> <td width="120" align="center"><img width="60" src="../bg.gif" height=<%= per3*400 %>></td> <td width="120" align="center"><img width="60" src="../bg.gif" height=<%= per4*400 %>></td> </tr> <tr height="25"> <td align="center">A</td> <td align="center">B</td> <td align="center">C</td> <td align="center">D</td> </tr> <tr height="25" align="center"> <td>得票率</td> <td><%= FormatNumber(per1*100,2,True) %>%</td> <td><%= FormatNumber(per2*100,2,True) %>%</td> <td><%= FormatNumber(per3*100,2,True) %>%</td> <td><%= FormatNumber(per4*100,2,True) %>%</td> </tr> <tr height="40" align="center"> <td>当前票数</td> <td colspan="4"><p style="color:red;letter-spacing:5px;"><%= Total %>票</p></td> </tr> </table> <p style="padding-right:180px;" align="right"><a href="../index.asp">back</a></p> </body> </html> <!-- 请求页面:index.asp --> <%@LANGUAGE="VBSCRIPT"%> <!--#include file="display.asp" --> <html> <head> <title>:: Local Station ::</title> <link href="style.css" rel="stylesheet" type="text/css"> </head> <body topmargin="50" onselectstart="return false" oncontextmenu=self.event.returnValue=false> <p style="padding-left:180px;font-family:华文行楷;font-size:15pt;">给我们投票:</p> <p style="padding-left:225px;font-family:华文行楷;font-size:13pt;"> :: <a href="voting.asp?vote=va">很好</a> :: <a href="voting.asp?vote=vb">一般</a> :: <a href="voting.asp?vote=vc">不是很好</a> :: <a href="voting.asp?vote=vd">不好</a> ::</p> <p style="padding-left:225px;font-family:华文行楷;font-size:13pt;"> 当前票数: <font color="red" size="3"> <%= Total %> </font> 票 <a href="vote.asp">查看投票结果</a>< /p> <hr size="1" color="#800000" noshade width="90%" align="center"> </body> </html> <!-- 错误处理页面: error.asp --> <% Dim id,error,why id = Request.QueryString("id") 'creating a querying string ... why = "可能的错误原因:" If id = "forbidden" Then error = "本页禁止访问,请与管理员联系 ..." ElseIf id = "001" Then error = "你已经为本站投过一票,请不要重复投票,谢谢合作 ..." Else error = "错误未知,请与管理员联系 ..." End If %> <div style="line-height:24pt;font-size:24pt;padding-left:180px;font-family:华文行楷;"> <p style="padding-left:120px;"> <%= why %> </p> <p style="padding-left:160px;"><font color="#804040"><%= error %></font></p> </div> <!-- 整个程序到此结束,还请不吝赐教…… -->
|