以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 DTD/XML Schema 』  (http://bbs.xml.org.cn/list.asp?boardid=23)
----  一个困扰了我一周的XML基础问题.前辈们请进.  (http://bbs.xml.org.cn/dispbbs.asp?boardid=23&rootid=&id=18816)


--  作者:digituser
--  发布时间:5/25/2005 3:10:00 PM

--  一个困扰了我一周的XML基础问题.前辈们请进.
需求描述:
学校有15个大大小小的学生用网站或FTP.现在希望建一个小型门户,把15个网站的内容聚合在一起.

遇到的问题:
可以遍历所有的元素并显示出来,但是希望通过定义CHANNEL的属性来提取需要显示的元素.

XML文件:
<?xml version="1.0" encoding="gb2312"?>
<data>
 <channel name="ftp1">
  <item>
    <title>我院评出学院优秀教师</title>
    <link>details.php?image_id=287</link>
  </item>
  <item>
    <title>我院组织教职员工周末外出旅游</title>
   <link>details.php?image_id=282</link>
  </item>
  <item>
    <title>项目开发经验齐分享</title>
   <link>newsShow.jsp?newsid=89</link>
  </item>
 </channel>
 
 <channel name="ftp2">
  <item>
   <title>FTP2测试1</title>
   <link>http://localhost</link>
  </item>
  <item>
    <title>我院评出学院优秀教师ftp2</title>
    <link>details.php?image_id=287</link>
  </item>
  <item>
    <title>我院组织教职员工周末外出旅游ftp2</title>
   <link>details.php?image_id=282</link>
  </item>
  <item>
    <title>项目开发经验齐分享ftp2</title>
   <link>newsShow.jsp?newsid=89</link>
  </item>
 </channel>
 
 <channel name="ftp3">
  <item>
   <title>FTP3测试1</title>
   <link>http://localhost</link>
  </item>
  <item>
    <title>我院评出学院优秀教师ftp3</title>
    <link>details.php?image_id=287</link>
  </item>
  <item>
    <title>我院组织教职员工周末外出旅游ftp3</title>
   <link>details.php?image_id=282</link>
  </item>
  <item>
    <title>项目开发经验齐分享ftp3</title>
   <link>newsShow.jsp?newsid=89</link>
  </item>
 </channel>
</data>


ASP文件:
<table width="764" height="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td>
<%
Set http=Server.CreateObject("Microsoft.XMLHTTP")
http.Open "GET","http://localhost/neusoft-2.xml",False
http.send

Set xml=Server.CreateObject("Microsoft.XMLDOM")
xml.Async=False
xml.ValidateOnParse=False
xml.Load(http.ResponseXML)
If xml.ReadyState>2 Then
        Response.Write("文档已经准备就绪。状态:"& xml.ReadyState &"<br>")
        Set channel=xml.getElementsByTagName("channel")
        //Set name = xml.getAttributeByName("name")
        Response.Write name
        Set item=xml.getElementsByTagName("item")
        For i=0 To (item.Length-1)
        Set title=item.Item(i).getElementsByTagName("title")
        Set link=item.Item(i).getElementsByTagName("link")
        Response.Write("<a href="""& link.Item(0).Text &""">"& title.Item(0).Text &"</a><br>")
        Next
Else
        Response.Write("文档还未准备就绪。状态:"& xml.ReadyState &"<br>")
End If
Set http=Nothing
Set xml=Nothing
%>
</td>
  </tr>
</table>

ASP部分的代码是网上找的.不知道如何进行判断,通过CHANNEL的NAME属性来读取数据.

期待回复.


--  作者:digituser
--  发布时间:5/25/2005 8:08:00 PM

--  
问题已自己解决:
<%
dim node,zxc,nodecount,node2,zx,nodecount2
Set http=Server.CreateObject("Microsoft.XMLHTTP")
http.Open "GET","http://localhost/neusoft-2.xml",False
http.send

Set xml=Server.CreateObject("Microsoft.XMLDOM")
xml.Async=False
xml.ValidateOnParse=False
xml.Load(http.ResponseXML)
If xml.ReadyState>2 Then
        Response.Write("文档已经准备就绪。状态:"& xml.ReadyState &"<br>")
        set root = xml.documentElement
    set nodeLis = root.childNodes
    nodeCount2 = nodeLis.length
    For zx=1 to nodeCount2
    set node2 = nodeLis.nextNode()
    set channel = node2.attributes.getNamedItem("name")
    %>
   <%=zx%>.
   
   <a href=<%=zx%> target="_blank"><%= channel.text%></a><br>
        
   <%
        Set item=node2.getElementsByTagName("item")
        For i=0 To (item.Length-1)
        Set title=item.Item(i).getElementsByTagName("title")
        Set link=item.Item(i).getElementsByTagName("link")
        Response.Write("<a href="""& link.Item(0).Text &""">"& title.Item(0).Text &"</a><br>")
        Next
        Next
Else
        Response.Write("文档还未准备就绪。状态:"& xml.ReadyState &"<br>")
End If
Set http=Nothing
Set xml=Nothing
%>


--  作者:anchen0617
--  发布时间:5/27/2005 8:50:00 AM

--  
好,自己解决了好。
--  作者:邪之正義
--  发布时间:5/27/2005 10:56:00 AM

--  
不錯啊!
--  作者:vida226500
--  发布时间:6/8/2005 8:58:00 PM

--  
搞不懂一头雾水,也没人对我指导!
--  作者:lembertyu
--  发布时间:9/1/2005 2:39:00 PM

--  
不错,还以为XML是什么呢,原来不能像HTML样独立使用。。。。
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
62.500ms