Ver Mensaje Individual
  #1 (permalink)  
Antiguo 03/03/2009, 04:03
machoman112233
Invitado
 
Mensajes: n/a
Puntos:
undefined method DOMElement::getElemetsByTagName()

Buenas!!! Intento hacer una script para sacar la informacion RSS de alguna pagina usando el DOMDocument. No encuentro la solucion al error. De paso me podeis decir si lo hago esta bien encamindo... es que nunca he tocado las rss...

PD: el codigo no esta todo comentado... aun esta en desarollo XDXDXD

Código php:
Ver original
  1. <?php
  2. class RSS_PHP
  3. {
  4.     var $xml;
  5.     var $load_dom;
  6.    
  7.     private $channel_atr = array();             //tags del canal.
  8.     var $channel_all = array();                 //toda la informacio que hay en el canal.
  9.     var $channel;                               //
  10.    
  11.     var $descript_nom = array();                //informacion sobre el contenido del tag <description> de cda  item.
  12.     var $descript;                              //
  13.    
  14.     var $title_nom = array();                   //informacion sobre el contenido del tag <title> de cda  item.
  15.     var $title;                                 //
  16.    
  17.     var $link_nom = array();                    //informacion sobre el contenido del tag <link> de cda  item.
  18.     var $link;                                  //
  19.    
  20.     private $item_atr = array();                //tags del item.
  21.     private $item_all = array();                //toda la informacion que hay en item.
  22.     var $item;                                  //
  23.    
  24.     function RSS_PHP()
  25.     {
  26.         //tags por defecto para channel.
  27.         $this -> channel_atr = array("title","link","description","language","pubDate",
  28.                         "lastBuildDate","docs","generator","managingEditor","webMaster");
  29.  
  30.         //tags por defecto para item
  31.         $this -> item_atr = array("title","link","description","pubDate","guid");
  32.     }
  33.    
  34.     function getRss($xml)
  35.     {
  36.         //comprueba que exite algo en la variable $xml.
  37.         //llama a la funcion de carga del xml
  38.         if(empty($xml)){return(False);}
  39.         else
  40.         {
  41.             $this->xml = $xml;
  42.             return($this->load_func());
  43.         }
  44.     }
  45.    
  46.     function load_func()
  47.     {
  48.         //carga el xml.
  49.         $this->load_dom = new DOMDocument;
  50.         $this->load_dom->load($this->xml);
  51.        
  52.         //comprueba que se ha cargado correctamete.
  53.         if(!$this->load_dom){return(False);}
  54.         else{return(True);}
  55.     }
  56.    
  57.     function getChannel()
  58.     {
  59.         $this->channel = $this->load_dom->getElementsByTagName("channel");
  60.     }
  61.    
  62.     function getItem()
  63.     {
  64.         $this->item = $this->load_dom->getElementsByTagName("item");
  65.     }
  66.    
  67.     function getChannelInfo($info)
  68.     {
  69.         if(empty($info)){$info = $this->channel_atr;}
  70.         foreach($this->channel as $canal)
  71.         {
  72.             for($ind = 0;$ind < count($info);$ind++)
  73.             {
  74.                 $information = $canal->getElementsByTagName($info[$ind]);
  75.                 if(isset($information->item(0)->nodeValue))
  76.                 {
  77.                     $this->channel_all[$info[$ind]] = $information->item(0)->nodeValue;
  78.                 }
  79.             }
  80.         }
  81.         return($this->channel_all);
  82.     }
  83.    
  84.     function getItemInfo($info)
  85.     {
  86.         if(empty($info)){$info = $this->item_atr;}
  87.         if(!isset($this->item)){$this->getItem();}
  88.         foreach($this->item as $item)
  89.         {
  90.             for($ind = 0;$ind < count($this->item);$ind++)
  91.             {
  92.                 for($ind2 = 0;$ind2 < count($info);$ind2++)
  93.                 {
  94.                     $tag = $item->getElemetsByTagName($info[$ind2]); //error aqui!!!! <------>
  95.                     if(isset($tag->item(0)->nodeValue))
  96.                     {
  97.                         $this->item_all[$ind][$info[$ind2]] = $tag->item(0)->nodeValue;
  98.                     }
  99.                 }
  100.             }
  101.         }
  102.         return($this->item_all);
  103.     }
  104.    
  105.     function getTitle()
  106.     {
  107.         if(!isset($this->item)){$this->getItem();}
  108.         $ind = 0;
  109.         foreach($this->item as $this->title)
  110.         {
  111.             $title = $this->title->getElementsByTagName("title");
  112.             $this->title_nom[$ind] = $title->item(0)->nodeValue;
  113.             $ind++;
  114.         }
  115.        
  116.         if(!empty($this->title_nom)){return($this->title_nom);}
  117.         else{return(False);}
  118.     }
  119.    
  120.     function getDescript()
  121.     {
  122.         if(!isset($this->item)){$this->getItem();}
  123.         $ind = 0;
  124.         foreach($this->item as $this->descript)
  125.         {
  126.             $descript = $this->descript->getElementsByTagName("description");
  127.             $this->descript_nom[$ind] = $descript->item(0)->nodeValue;
  128.             $ind++;
  129.         }
  130.        
  131.         if(!empty($this->descript_nom)){return($this->descript_nom);}
  132.         else{return(False);}
  133.     }
  134. }
  135.  
  136. /*$rss = new RSS_PHP;
  137. $rss->getRss("http://www.amposta.cat/rss.asp");
  138. $item = $rss->getItemInfo("");
  139. print_r($item);*/
  140. ?>