技術(shù)小結(jié):
asp中創(chuàng)建xml對象通常使用:CreateObject("Microsoft.XMLDOM")
讀取節(jié)點:selectSingleNode("nodename")//nodename為節(jié)點名。
讀取屬性:attributes.getNamedItem("attribute")//attribute為節(jié)點中所具有的屬性名。
加載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>上??萍汲霭嫔?lt;/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>
|
|
該文章在 2012/7/9 8:33:29 編輯過