js,asp 实现读取远程xml

 js 实现读取远程xml
 <script language="JavaScript">
   var xmlDoc=new ActiveXObject("Microsoft.xmlDOM");
   xmlDoc.async=false;
   xmlDoc.load("http://www.donews.com/rss.xml");
   //xmlDoc.loadxml("<description>品格</description>");

   var root=xmlDoc.documentElement;
    var number=root.selectNodes("channel/item").length;

  if(number<=10)
     alert("对不起,该新闻条数已经少于要显示的新闻条数!"); 
  else
   {
      document.writeln("<p align='center' class='font'>"+root.childNodes(0).childNodes(0).text+"<p>");    
      document.writeln("<p class='indent'>"+root.childNodes(0).childNodes(1).text+"</p>");
      document.writeln("<p class='indent'>"+root.childNodes(0).childNodes(2).text+"</p>");
     for(var i=0;i<10;i++)
  {
   document.writeln("<b>"+root.childNodes(0).childNodes(5+i).childNodes(0).text+"</b><br/><br/>");
document.writeln("<small>"+root.childNodes(0).childNodes(5+i).childNodes(4).text+"&nbsp;&nbsp;&nbsp;&nbsp;"+root.childNodes(0).childNodes(5+i).childNodes(3).text+"</small><br/>");
document.writeln("<small><a href='"+root.childNodes(0).childNodes(5+i).childNodes(1).text+"'>"+root.childNodes(0).childNodes(5+i).childNodes(1).text+"</a></small><br/><br/>");
document.writeln("<p class='indent'>"+root.selectNodes("channel/item/description")(i).text+"</p><br/><br/>");
   }
  }
</script>

 asp 实现读取远程xml文件
<%
dim xmlDoc
dim root
dim number

Set http=Server.CreateObject("Microsoft.XMLHTTP")
http.Open "GET","http://www.donews.com/rss.xml",False
http.send

Set xmlDoc=Server.CreateObject("Microsoft.XMLDOM")
xmlDoc.Async=False
xmlDoc.ValidateOnParse=False
xmlDoc.Load(http.ResponseXML)

set root=xmlDoc.documentElement
number=root.selectNodes("channel/item").length

 if number<=10 then
%>
  <script language="vbscipt">
    msgbox "对不起,该新闻条数已经少于要显示的新闻条数!"
  </script>
<%
  else
      response.write "<p align='center' class='font'>" & root.childNodes(0).childNodes(0).text & "<p>"    
      response.write "<p class='indent'>" & root.childNodes(0).childNodes(1).text & "</p>"
      response.write "<p class='indent'>" & root.childNodes(0).childNodes(2).text & "</p>"
    for i=0 to 9
   response.write "<b>" & root.childNodes(0).childNodes(5+i).childNodes(0).text & "</b><br/><br/>"
response.write "<small>" & root.childNodes(0).childNodes(5+i).childNodes(4).text & root.childNodes(0).childNodes(5+i).childNodes(3).text & "</small><br/>"
response.write "<small><a href='" & root.childNodes(0).childNodes(5+i).childNodes(1).text & "'>" & root.childNodes(0).childNodes(5+i).childNodes(1).text & "</a></small><br/><br/>"
response.write "<p class='indent'>" & root.selectNodes("channel/item/description")(i).text & "</p><br/><br/>"
  next
  end if
%>

 

posted @ 2006-12-13 17:26  Winner.Net(2007)  阅读(2400)  评论(0编辑  收藏  举报