asp操作xml实例

这次作业的第二个要求是将生成的xml文件通过asp解析后以表格形式输出,其实都很简单的操作,对于节点,只要你能很明白的把它当作一棵树,时刻知道自己正在操作的几点位于什么位置就好了,在这次的内容中,我的代码有一部分是注释掉的,从那些注释的内容就可以看出,其实我也不是学习asp的人,纯粹是课程作业的要求,所以更多的代码写的过程中都是一步步尝试得来的,根据自己js上操作的经验,班门弄斧了,废话不多说,直接看代码(这个可是完整代码,不想把代码再弄乱)。

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%
Set xmlDoc = Server.CreateObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load(Server.MapPath("aspXml2.xml"))
Set roots = xmlDoc.documentElement
Set childs = roots.childNodes

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>asp解析XML文档</title>
</head>

<body>

<table width="80%" style="border-collapse:collapse" border="1" id="myTable">
    <tr>
        <th>序号</th>
        <th>标题</th>
        <th>内容</th>
        <th>作者</th>
        <th>时间</th>
        <th>回复</th>
        <th>回复内容</th>
        <th>地址</th>
    </tr>
    <%
    for i = 0 to childs.length – 1
    %>
    <tr>
        <td><%=childs(i).childNodes(0).text%></td>
        <td><%=childs(i).childNodes(1).text%></td>
        <td><%=childs(i).childNodes(2).text%></td>
        <td><%=childs(i).childNodes(3).text%></td>
        <td><%=childs(i).childNodes(4).text%></td>
        <td><%=childs(i).childNodes(5).text%></td>
        <td><%=childs(i).childNodes(6).text%></td>
        <td><%=childs(i).childNodes(7).text%></td>
        <!–
        这些写法都可以实现遍历,选择最简单的一种
        好像asp中不能使用.nodeValue来获取值
        <td><%’=childs(i).firstChild.nextSibling.text%></td>
        <td><%’=childs(i).firstChild.nextSibling.nextSibling.text%></td>
        <td><%’=childs.item(i).childNodes.item(3).text%></td>
        <td><%’=childs.item(i).childNodes.item(4).text%></td>
        <td><%’=childs.item(i).childNodes.item(5).text%></td>
        <td><%’=childs.item(i).childNodes.item(6).text%></td>
        <td><%’=childs.item(i).childNodes.item(7).text%></td>–>
    </tr>
    <%
    next
    %>
</table>

</body>
</html>



文章来自: 本站原创
Tags:
评论: 0 | 查看次数: 5734