asp如何读取XML?
asp如何读取XML?我想要一个xml的文件,一个asp的文件,让asp文件能读取xml文件的内容!...
asp如何读取XML?
我想要一个xml的文件,一个asp的文件,让asp文件能读取xml文件的内容! 展开
我想要一个xml的文件,一个asp的文件,让asp文件能读取xml文件的内容! 展开
展开全部
ASP文件:
<%Response.Charset="gb2312"%>
<html>
<title>read xml</title>
<body>
<%
dim node,i,nodecount
set xml = CreateObject("Microsoft.XMLDOM")
xml.async = false
xml.load(Server.MapPath("data.xml"))
set root = xml.documentElement
set nodeLis = root.childNodes
nodeCount = nodeLis.length
For i=1 to nodeCount
set node = nodeLis.nextNode()
set cost = node.attributes.getNamedItem("cost")
%>
第 <%=i%> 条记录:
<table width="250" border="1">
<tr>
<td>书名</td>
<td>出版社</td>
<td>价格</td>
</tr>
<tr>
<td>
<%=node.selectSingleNode("name").text%></td>
<td>
<%=node.selectSingleNode("publisher").text%></td>
<td>
<%= node.selectSingleNode("cost").text%></td>
</tr>
</table>
<%
Next
%>
</body>
</html>
XML文件《data.xml》:
<?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>
<%Response.Charset="gb2312"%>
<html>
<title>read xml</title>
<body>
<%
dim node,i,nodecount
set xml = CreateObject("Microsoft.XMLDOM")
xml.async = false
xml.load(Server.MapPath("data.xml"))
set root = xml.documentElement
set nodeLis = root.childNodes
nodeCount = nodeLis.length
For i=1 to nodeCount
set node = nodeLis.nextNode()
set cost = node.attributes.getNamedItem("cost")
%>
第 <%=i%> 条记录:
<table width="250" border="1">
<tr>
<td>书名</td>
<td>出版社</td>
<td>价格</td>
</tr>
<tr>
<td>
<%=node.selectSingleNode("name").text%></td>
<td>
<%=node.selectSingleNode("publisher").text%></td>
<td>
<%= node.selectSingleNode("cost").text%></td>
</tr>
</table>
<%
Next
%>
</body>
</html>
XML文件《data.xml》:
<?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>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询