asp中创建xml对象通常使用:CreateObject("Microsoft.XMLDOM")
读取节点:selectSingleNode("nodename")//nodename为节点名。
读取属性:attributes.getNamedItem("attribute")//attribute为节点中所具有的属性名。
加载xml; load(Server.MapPath("data.xml"))
async 属性表示是否允许异步的下载。
引用:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%Response.Charset="UTF-8"%>
<html>
<title>read xml</title>
<body>
<%
dim node,i,nodecount
set Doc = CreateObject("Microsoft.XMLDOM")
Doc.async = false
Doc.load(Server.MapPath("data.xml"))
set root = Doc.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 border="1">
<tr>
<td width="16" rowspan="2"><img src="<%=node.selectSingleNode("img").text%>"/></td>
<td width="17">书名</td>
<td width="48">出版社</td>
<td width="32">价格</td>
</tr>
<tr>
<td>
<%=node.selectSingleNode("name").text%>
</td>
<td>
<%=node.selectSingleNode("publisher").text%>
</td>
<td>
<%= cost.text%>
</td>
</tr>
</table>
<%
Next
%>
</body>
</html>
XML
引用:
<?xml version="1.0" encoding="utf-8"?>
<data>
<book cost="56">
<name>Dreamweaver</name>
<publisher>上海科技出版社</publisher>
<img>img/dw.jpg</img>
</book>
<book cost="62">
<name>Flash</name>
<publisher>铁道出版社</publisher>
<img>img/flash.jpg</img>
</book>
<book cost="48">
<name>Firweorks</name>
<publisher>教育出版社</publisher>
<img>img/fw.jpg</img>
</book>
</data>
posted on 2006-08-07 16:54
汪杰 阅读(567)
评论(1) 编辑 收藏 引用 所属分类:
xml