ASP XMLDom在服务器端操作XML文件的主要方法和实现(3)


response.write element.nodevalue 属性值
next

等能够熟练的运用xmldom对象来操作xml文件了,就可以享受xmlhttp对象来实现asp下的许多功能了。

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

虽然asp只能简单的操作XML文件,可是对于一般程序开发者来说就已经足够。
之前,XML语言非常的少接触,后来慢慢的,发觉XML在存储数据上有很多的方便。虽然安全性不好(个人认为),可是对于一般的数据存储的确 是一个非常不错的选择。
今天因为在一个网站上需要用到XML,我在这里就做一些总结(后期将会用到):
==============
首先,先整理ASP读取XML文件
default.asp的代码
<%
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 width="50%" border="1">
<tr>
<td width="43" rowspan="2"><img src="<%=node.selectSingleNode("img").text%>"/></td>
<td width="46">书名</td>
<td width="48">出版社</td>
<td width="42">价格</td>
</tr>
<tr>
<td>
<%=node.selectSingleNode("name").text%>
</td>
<td>
<%=node.selectSingleNode("publisher").text%>
</td>
<td>
<%= cost.text%>
</td>
</tr>
</table>
<%
Next
%>
====================
接下来就是Data.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>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/2397.html