您的位置:程序门 -> web 开发 -> xml/soap



地址已经可以传到test事件内的对象了。。。怎么读地址内的内容就可以了(救命啊)


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


地址已经可以传到test事件内的对象了。。。怎么读地址内的内容就可以了(救命啊)
发表于:2007-09-06 09:59:36 楼主
//a.html

<html>
<head>
            <title> javascript读取rss数据 </title>
    <meta   content= "text/html;   charset=utf-8 "   http-equiv=content-type   />
</head>
<body     leftmargin= "0 "   topmargin= "0 ">  
<font> <h3   align= "center "> javascript读取rss数据 </h3> </font>
<br>    
<div   id= "container "   > news   loading... </div>
<div   id= "container0 "   > news   loading... </div>
<script   language= "javascript1.2 ">
var   xmlsource= "test.xml ";
var   root;
var   title;
var   link;  
var   items;
var   item;
if   (window.activexobject)
{
    //document.write( "microsoft.xmldom ");
    var   xmldoc   =   new   activexobject( "microsoft.xmldom ");
}
else   if   (document.implementation   &&   document.implementation.createdocument)
{
    //document.write( "document.implementation.createdocument ");
    var   xmldoc=   document.implementation.createdocument( " ", "doc ",null);
}
if   (typeof   xmldoc!= "undefined ")
{
    //document.write(tickercontainer)
    xmldoc.load(xmlsource)
    //alert(xmldoc);
}    
function   fetchxml()
{
    if   (xmldoc.readystate==4)
//document.write( "fdfdf ");
      output();
    else
      settimeout( "fetchxml() ",10);
}
function   test(a){
//注.这里a不是本网站的地址而是订阅的地址
var   source=a;
//var   xmlsource= "test.xml ";
var   root;
var   title;
var   link;  
var   items;
var   item;
var   description;

var   temp= " ";
var   xmldoc   =   new   activexobject( "microsoft.xmldom ");
xmldoc.load(xmlsource)

    root   =   xmldoc.getelementsbytagname( "channel ")[0];

//alert(source);
    title   =root.getelementsbytagname( "title ")[0];
    //temp   =   title.firstchild.nodevalue   + " <br> ";
    items=root.getelementsbytagname( "item ");
    //alert(items);
    for(i=0;i <=items.length-1;i++)

    {
      item=items[i];
      title=item.getelementsbytagname( "title ")[0];  
      link=item.getelementsbytagname( "link ")[0];
      description=item.getelementsbytagname( "description ")[0];
      //alert(description);
      category=item.getelementsbytagname( "category ")[0];
      pubdate=item.getelementsbytagname( "pubdate ")[0];
      temp   =   temp   +   " <font   size=-1> <a   href= "   +   link.firstchild.nodevalue+   "   target= '_bank '> "   +title.firstchild.nodevalue+ " <br> "+category.firstchild.nodevalue+pubdate.firstchild.nodevalue+ " </a> </font> <br> <br> ";
      //temp   =   temp   + " <font   size=-1> "   +   description.firstchild.nodevalue   +   " </font> <br> <br> ";
      document.getelementbyid( "container ").innerhtml   =   temp;
    }
    settimeout(1000);
      return;
}
   
function   output()
{    
    var   temp= " ";
    root   =   xmldoc.getelementsbytagname( "channel ")[0];
    title   =root.getelementsbytagname( "title ")[0];
    //temp   =   title.firstchild.nodevalue   + " <br> ";
    items=root.getelementsbytagname( "item ");
   
    for(i=0;i <=items.length-1;i++)
    {
      item=items[i];
     
      title=item.getelementsbytagname( "title ")[0];  
      link=item.getelementsbytagname( "link ")[0];
     
  //alert(link.firstchild.nodevalue);
      temp   =   temp   +   " <font   size=-1> <a   href= "   +   link.firstchild.nodevalue+   "   target= '_bank '> "   +title.firstchild.nodevalue+ " <br> "+ " </a> </font> ";
      //temp   =   temp   + " <font   size=-1> "   +   description.firstchild.nodevalue   +   " </font> <br> <br> ";
      document.getelementbyid( "container0 ").innerhtml   =   temp;
      test(link.firstchild.nodevalue);
    }
    //settimeout(output(),1000)
}
if   (window.activexobject){
    fetchxml();
    }
else   if   (typeof   xmldoc!= "undefined "){
    xmldoc.onload=output;}
   
</script>
</body>
</html>


//test.xml

<channel>
<item> <title> 新华信息 </title> <link> http://rss.xinhuanet.com/rss/it.xml </link> </item>
<item> <title> 新浪新闻 </title> <link> http://rss.sina.com.cn/news/china/focus15.xml </link> </item>
<item> <title> 新浪世界 </title> <link> http://rss.sina.com.cn/news/world/focus15.xml </link> </item>

</channel>


地址已经可以传到test事件内的对象了。。。怎么读地址内的内容就可以了。。


发表于:2007-09-06 10:21:461楼 得分:0
莫名其妙的问题。
你代码不就是吗?

以后提问尽量针对具体的点进行。


快速检索

最新资讯
热门点击