mud_sanc 板


LINE

最近在公司以单纯的 ASP(非 ASP.NET) 写了两支程式,这里 做个分享。以底下的 xml 为例 <sanc> <playerdata> <player> <id>laechan</id> <level>120</level> <race>human</race> </player> <player> <id>norr</id> <level>120</level> <race>devil</race> </player> </playerdata> </sanc> 我使用 response.cookies 的方式(简单的说就是土法炼钢) 来储存上面的资讯,做法如下... <% ' 先 create 一个 xml 用的物件 Set Https = Server.CreateObject("MSXML2.XMLHTTP") ' 把这个物件设为指向打开下列网址的 xml 资料传送用物件 ' 然後把资料 send 给它(new_str 就是我编好的 xml 东西) Https.open "POST","http://网址/api",false Https.send new_str ' 若传送有成功(state=4)就执行底下 if Https.readystate=4 then ' create 出一个存放 xml 资料的物件 set xml = Server.CreateObject("MSXML2.DOMDocument") xml.Async = false ' 让这个物件去做 loadXML 的动作, 其目标是从上述网址 ' response 回来的东西, 假设就是我上面打的那一串 xml xml.loadXML Https.ResponseText ' 下面这个动作, 可以把「每一个」 <player> ... </player> ' 里面的东西捞出来存放到 players 里头,类似底下这样 ' players = ({ ({"laechan","120","human"}), ({"norr","120","devil"}),.. }) set players = xml.getElementsByTagName("player") ' 这个类似 sizeof(players) < 1 的判断式 if players.length < 1 then response.write "没有捞到任何资料喔.<p>" ' 底下类似程式执行到这里就 end 掉(结束) response.end end if ' 把 k 存成长度的整数, 我实测过若不经过这个转换 ' players.length 无法被判断为整数, 很怪 k = CInt(players.length) dim keyname(100) for i = 0 to k-1 ' playerxml = 每一笔 <player> ... </player> set playerxml = player.item(i) ' playerxml 的第 0 笔资料就是 <id> 资料 ' 令 playerid = 该值而且强制其变成字串 ' .childNodes(n) 就是取出第 n 笔子节点, .text 代表取出节点的值 playerid = CStr(playerxml.childNodes(0).text) ' 并把每一个 playerid 另外存起来 keyname(i) = playerid ' 接着, 就去捞每一个 <player> ... </player> 底下的子节点 ' 也就是 <id> , <level>, <race> 那些 for each nodes in playerxml.childNodes ' 取得子节点名字, 就是 "id", "level", "race" 等 ' 上面的 for each nodes 的目的就是为了取得 nodes 这个东西 tmp=CStr(nodes.NodeName) ' 把资料用类似 mapping 的方式存起来 ' cookies("laechan")("level") = "120" 这样 response.cookies(playerid)(tmp) = playerxml.childNodes(j).text next next end if 到这里就读完了,接着就是验证结果 strs = "<table border=1><tr><th>玩家ID</th><th>等级</th><th>种族</th></tr>" for i = 0 to k-1 playerid = keyname(i) ' 底下就类似 strs = strs + xxx strs = strs & "<tr><th>" & request(playerid)("level") & "</th>" strs = strs & "<tr><th>" & request(playerid)("race") & "</th></tr>" next response.write strs & "</table>" %> 其网页执行结果就类似底下 ┌────┬──┬───┐ │ 玩家ID │等级│ 种族 │ ├────┼──┼───┤ │laechan │120 │human │ ├────┼──┼───┤ │norr │120 │devil │ └────┴──┴───┘ 跟自己熟悉的语言对照一下就能理解上面的写法,这是一种土法 炼钢的方式,为的就是以最快的速度开发出我想要的东西。 LAechan --



※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 114.26.188.94







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:Tech_Job站内搜寻

TOP