ASP 读取xml数据

发布时间:2010年03月18日      浏览次数:713 次
------------------------------------
xml.asp 文件代码
------------------------------------
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<table width="200" border="1" cellpadding="4" cellspacing="0" bordercolor="#CCCCCC" bordercolordark="#ffffff">
<tr>
      <td width="100" height="25" nowrap="nowrap" bgcolor="#efefef"><b>ID</b></td>
      <td width="100" height="25" nowrap="nowrap" bgcolor="#efefef"><b>标题</b></td>
</tr>
<%
response.Charset = "utf-8"
Dim strSourceFile, objXML, objRootsite, AllNodesNum
strSourceFile = Server.MapPath("test.xml")
Set objXML = Server.CreateObject("Microsoft.XMLDOM")
objXML.Load (strSourceFile)
Set objRootsite = objXML.documentElement.selectSingleNode("web")
AllNodesNum = objRootsite.childNodes.length - 1
Dim iCount
For iCount = 0 To AllNodesNum
%>
<tr>
      <td width="100" height="25" nowrap="nowrap"> <%=objRootsite.childNodes.item(iCount).childNodes.item(0).text%></td>
      <td width="100" height="25" nowrap="nowrap"> <%=objRootsite.childNodes.item(iCount).childNodes.item(1).text%></td>
</tr>
<%
Next
Set objRootsite = Nothing
Set objXML = Nothing
%>
</table>
------------------------------------
test.xml 文件内容
------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<xml>
<web>
<items><id>1</id><txt>网站建设</txt></items>
<items><id>2</id><txt>优化推广</txt></items>
<items><id>3</id><txt>技术支持</txt></items>
<items><id>4</id><txt>友情链接</txt></items>
<items><id>5</id><txt>广告服务</txt></items>
<items><id>6</id><txt>域名空间</txt></items>
</web>
</xml>
免责声明:本站相关技术文章信息部分来自网络,目的主要是传播更多信息,如果您认为本站的某些信息侵犯了您的版权,请与我们联系,我们会即时妥善的处理,谢谢合作!