如何从XML中按条件取出数据?

来源:百度知道 编辑:UC知道 时间:2024/05/14 06:42:14
比如下面的XML文件,我只要cost=48 的两条记录,用ASP应该怎么操作呀?

<?xml version="1.0" encoding="gb2312"?>
<data>
<book>
<cost>48</cost>
<name>Dreamweaver</name>
<publisher>上海科技出版社</publisher>
<img>img/dw.jpg</img>
</book>
<book>
<cost>61</cost>
<name>Flash</name>
<publisher>铁道出版社</publisher>
<img>img/flash.jpg</img>
</book>
<book>
<cost>48</cost>
<name>Firweorks</name>
<publisher>教育出版社</publisher>
<img>img/fw.jpg</img>
</book>
</data>

输出效果:

1: 48 Dreamweaver 上海科技出版社 img/dw.jpg
2: 48 Firweorks 教育出版社 img/fw.jpg

-------------------------------------------------

<%
dim xmldoc,nodeList,node,cnt,tot
set xmldoc = Server.CreateObject("microsoft.xmldom")
xmldoc.async = false
xmldoc.load(Server.MapPath("你的XML文件名.xml"))

set nodeList = xmldoc.selectNodes("//book[cost='48']")
tot = nodeList.length-1
for cnt=0 to tot step 1
set node = nodeList.nextNode()
Response.Write(cnt+1&": "&node.Text&"<br>")
next
set xmldoc = nothing
%>