100分!asp中如何远程读取xml文件?在线等

phyllis2001 2004-12-06 03:54:58
比如目标的网址如下:http://members.macauslot.com/nba/html/result/live.xml
请教高手这样把里面的诸如 fid="10734" sid="1" m="12" s="00" hsum="0" asum="0" HHS2="0" AHS2="0"里面的“”内的内容读出来,比如sid="1",我只想取1,其他的不要~~?

在线等~~
...全文
962 29 打赏 收藏 转发到动态 举报
写回复
用AI写文章
29 条回复
切换为时间正序
请发表友善的回复…
发表回复
dh20156 2004-12-08
  • 打赏
  • 举报
回复
假如http://members.macauslot.com/nba/html/result/live.xml文件格式如下:
<?xml version="1.0" encoding="gb2312"?>
<DATA>
<ROW num="1">
<TOURNAMENT_NAME>NCAA</TOURNAMENT_NAME>
<GAME_TIME>08:00</GAME_TIME>
<NAME1>匹茲堡</NAME1>
<NAME2>孟菲斯</NAME2>
<HCAP>3.5</HCAP>
<TOTALPOINTS>136.5</TOTALPOINTS>
</ROW>
<ROW num="2">
<TOURNAMENT_NAME>NBA</TOURNAMENT_NAME>
<GAME_TIME>08:00</GAME_TIME>
<NAME1>騎士</NAME1>
<NAME2>籃網</NAME2>
<HCAP>9</HCAP>
<TOTALPOINTS>177.5</TOTALPOINTS>
</ROW>
<ROW num="3">
<TOURNAMENT_NAME>NBA</TOURNAMENT_NAME>
<GAME_TIME>09:00</GAME_TIME>
<NAME1>木狼</NAME1>
<NAME2>小牛</NAME2>
<HCAP>6.5</HCAP>
<TOTALPOINTS>203.5</TOTALPOINTS>
</ROW>
</DATA>

以下示例如何取得所有node及它们的值:
TRY:
<%
Set objXML = server.CreateObject("Microsoft.XMLHTTP")
objXML.Open "Get", "http://members.macauslot.com/nba/html/result/live.xml",False
objXML.send
Banner = objXML.responseText
Set objXML = nothing

Set xml = Server.CreateObject("MSXML.DOMDocument")
xml.async = False
xml.loadXML Banner

Set root = xml.documentElement
for i = 0 to (root.childNodes.length-1)
for n = 0 to (root.childNodes.item(i).childNodes.length-1)
response.write root.childNodes.item(i).childNodes.item(n).baseName&":"
response.write root.childNodes.item(i).childNodes.item(n).text&"<br>"
next
next

Set xml=Nothing %>

你如果仅仅要取某一项或几项那你自己去改i或n的值。
dh20156 2004-12-08
  • 打赏
  • 举报
回复
你这个XML没有顶层元素啊(根结点)
dh20156 2004-12-08
  • 打赏
  • 举报
回复
for i = 0 to (root.childNodes.length-1)
response.write root.childNodes.item(i).childNodes.item(4).baseName&":"
response.write root.childNodes.item(i).childNodes.item(4).text&"<br>"
next
phyllis2001 2004-12-08
  • 打赏
  • 举报
回复
to:dh20156(风之石),非常感谢dh20156(风之石)!!!,小弟还有一疑问,再麻烦一下风之石这位大哥,上面那段代码可以拿到所以数据,可我只要其中某一部分就行了,比如我只想取<HCAP>3.5</HCAP>的值,按你说的,我改了n的值,
改成
response.write root.childNodes.item(i).childNodes.item(4).baseName&":"
response.write root.childNodes.item(i).childNodes.item(4).text&"<br>"

运行后,一方面数据可以显示出来,一方面却出现下面的错误

Microsoft VBScript 编译器错误 错误 '800a03f6'

缺少 'End'

/iisHelp/common/500-100.asp,行242

Microsoft VBScript 运行时错误 错误 '800a01a8'

缺少对象: 'root.childNodes.item(...).childNodes.item(...)'


请问这么解决???
phyllis2001 2004-12-07
  • 打赏
  • 举报
回复
根节点?可我找了半天,也没发现在xml文件里面有这东西啊?而且在上面那段代码里面,也没有定义过,感觉怪怪的,呵呵,别笑我啊,我不会xml拉,问的问题比较菜:(

那像我说的这种应该怎么捉呢?
<ROW num="1">
<TOURNAMENT_NAME>NCAA</TOURNAMENT_NAME>
<GAME_TIME>08:00</GAME_TIME>
<NAME1>匹茲堡</NAME1>
<NAME2>孟菲斯</NAME2>
<HCAP>3.5</HCAP>
<TOTALPOINTS>136.5</TOTALPOINTS>
</ROW>
<ROW num="2">
<TOURNAMENT_NAME>NBA</TOURNAMENT_NAME>
<GAME_TIME>08:00</GAME_TIME>
<NAME1>騎士</NAME1>
<NAME2>籃網</NAME2>
<HCAP>9</HCAP>
<TOTALPOINTS>177.5</TOTALPOINTS>
</ROW>
<ROW num="3">
<TOURNAMENT_NAME>NBA</TOURNAMENT_NAME>
<GAME_TIME>09:00</GAME_TIME>
<NAME1>木狼</NAME1>
<NAME2>小牛</NAME2>
<HCAP>6.5</HCAP>
<TOTALPOINTS>203.5</TOTALPOINTS>
</ROW>
我想把里面的的球队名字取出来,其他的不要???
yqh1314 2004-12-07
  • 打赏
  • 举报
回复
嘘唏!!!!!!学习!
dh20156 2004-12-07
  • 打赏
  • 举报
回复
//livescore 指的是根结点
phyllis2001 2004-12-07
  • 打赏
  • 举报
回复
to:dh20156(风之石)
dh20156(风之石),能不能解释一下 "//LIVESCORE/DATA/ROW" 这句代码是怎么用的,后面的data/row我可以理解,但//livescore这个呢???不明白是什么意思,还有,如果目标页面的代码换成如下这种格式的,该怎么捉?我换成
test = xml.selectSingleNode("//LIVESCORE/DATA/ROW["&i&"]").getAttribute("<GAME_TIME>")
运行不了~~
就差怎么一点拉,麻烦大家帮帮忙拉~~谢谢~~~

ROW num="1">
<TOURNAMENT_NAME>NCAA</TOURNAMENT_NAME>
<GAME_TIME>08:00</GAME_TIME>
<NAME1>匹茲堡</NAME1>
<NAME2>孟菲斯</NAME2>
<HCAP>3.5</HCAP>
<TOTALPOINTS>136.5</TOTALPOINTS>
</ROW>
<ROW num="2">
<TOURNAMENT_NAME>NBA</TOURNAMENT_NAME>
<GAME_TIME>08:00</GAME_TIME>
<NAME1>騎士</NAME1>
<NAME2>籃網</NAME2>
<HCAP>9</HCAP>
<TOTALPOINTS>177.5</TOTALPOINTS>
</ROW>
<ROW num="3">
<TOURNAMENT_NAME>NBA</TOURNAMENT_NAME>
<GAME_TIME>09:00</GAME_TIME>
<NAME1>木狼</NAME1>
<NAME2>小牛</NAME2>
<HCAP>6.5</HCAP>
<TOTALPOINTS>203.5</TOTALPOINTS>
</ROW>

dh20156 2004-12-07
  • 打赏
  • 举报
回复
TRY:
<%
Set objXML = server.CreateObject("Microsoft.XMLHTTP")
objXML.Open "Get", "http://members.macauslot.com/nba/html/result/live.xml",False
objXML.send
Banner = objXML.responseText
Set objXML = nothing

Set xml = Server.CreateObject("MSXML.DOMDocument")
xml.async = False
xml.loadXML Banner
n = xml.selectNodes("//LIVESCORE/DATA/ROW").length
for i = 0 to n-1
test = xml.selectSingleNode("//LIVESCORE/DATA/ROW["&i&"]").getAttribute("fid")
response.write test&";"
next
Set xml=Nothing %>
arbeng2002 2004-12-07
  • 打赏
  • 举报
回复
帮忙顶一下
phyllis2001 2004-12-07
  • 打赏
  • 举报
回复
to: dh20156(风之石) (
楼上的,你那段代码不行啊,能不能给我完整一点的呢?我xml不会啊,麻烦帮帮忙~~~谢谢
dh20156 2004-12-07
  • 打赏
  • 举报
回复
ROW[0]-->ROW["&i&"]
dh20156 2004-12-07
  • 打赏
  • 举报
回复
参考:
xmlfile="http://members.macauslot.com/nba/html/result/live.xml"
Set xml = Server.CreateObject("MSXML.DOMDocument")
xml.async = False
xml.load xmlfile
n = xml.selectNodes("//LIVESCORE/DATA/ROW").length
for i = 0 to n-1
fid = xml.selectSingleNode("//LIVESCORE/DATA/ROW[0]").getAttribute("fid")
next
luotofeng 2004-12-07
  • 打赏
  • 举报
回复
李强哥。我想加你QQ啊。我觉得你你很愿意帮助人啊。加我啦。谢谢270707672
phyllis2001 2004-12-07
  • 打赏
  • 举报
回复
to:李强

非常感谢李兄的指点,不过小弟还有一问,像上面那一段
response.write "第"& i+1 &"列sid=" & getstr(Rows(i),"sid=""",""" m=")&"<br>"
因为那个xml文件是动态的,比如我想捉h1,h2,h3,h4的值,但有时候时间没到,h4这个标记并没有出现在文件里,这样的话,上面那段代码如果设置为捉h4的值,程序就出错了,不知道有没有办法,在这种情况下,如果找不到那个标记,就自动输出h4=0呢?

希望李兄能再帮帮忙,也希望会的高手帮帮忙,万分感谢~~~~
lienzhu 2004-12-07
  • 打赏
  • 举报
回复
getStr(content,bstr,estr)
函数介绍

content要截取的字符串
bstr截取部分 前面关键字符串
estr截取部分 后面关键字符串
返回截取部分
lienzhu 2004-12-07
  • 打赏
  • 举报
回复
<%
function codeChange(str)
finalstr = ""
for i = 1 to lenb(str)
icharcode = ascb(midb(str,i,1))
if icharcode < &H80 then
finalstr = finalstr & chr(icharcode)
else
inextcode = ascb(midb(str,i+1,1))
finalstr = finalstr & chr(clng(icharcode) * &H100 + cint(inextcode))
i = i + 1
end if
next
codeChange = finalstr
end function
function getStr(content,bstr,estr)
Pstart=instr(content,bstr)+len(bstr)
Slen=instr(content,estr)-Pstart
tmpstr=mid(content,Pstart,Slen)
tmpstr=replace(tmpstr,vbcrlf,"")
tmpstr=replace(tmpstr,chr(10),"")
getStr=trim(tmpstr)
end function

set connect = createobject("Microsoft.XMLHTTP")
call connect.open ("GET","http://members.macauslot.com/nba/html/result/live.xml",false)
connect.send()
code = codeChange(connect.responsebody)
code=getstr(code,"<DATA>","</DATA>")
code=replace(code,"<","")
Rows=split(code,">")
for i=0 to ubound(Rows)-1
response.write "第"& i+1 &"列sid=" & getstr(Rows(i),"sid=""",""" m=")&"<br>"
next
%>
dachangtui 2004-12-06
  • 打赏
  • 举报
回复
很简单的嘛。
既然已经能读取到整页代码了,再随便写几个字符串处理语句就能得到想要的数据了。
擒兽 2004-12-06
  • 打赏
  • 举报
回复
mark
lienzhu 2004-12-06
  • 打赏
  • 举报
回复
<html><head>
<script language="JavaScript" for="window" event="onload">
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false";
xmlDoc.load("http://members.macauslot.com/nba/html/result/live.xml");
nodes=xmlDoc.documentElement.selectSingleNode("//DATA").childNodes
Content = "";
for(i=0;i<nodes.length;i++)
{
Content += "标签名称:" + nodes.item(i).nodeName + "<br>";
for(j=0;j<nodes.item(i).attributes.length;j++)
{
Content += "  " + nodes.item(i).attributes.item(j).nodeName + ":" + nodes.item(i).attributes.item(j).value
Content +="<br>"
}

Content +="<br>";
}

msg.innerHTML = Content;
</script>
<title>在HTML中调用XML数据</title>
</head>
<body><div id=msg></div></body>
</html>
加载更多回复(9)

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧