Ver Mensaje Individual
  #2 (permalink)  
Antiguo 07/07/2008, 18:53
Avatar de WyLY
WyLY
 
Fecha de Ingreso: enero-2002
Ubicación: Cancun, México.
Mensajes: 506
Antigüedad: 22 años, 3 meses
Puntos: 6
Respuesta: parsear xml...

Hola amigo, yo no sé mucho de xml, pero sé algo de php y ya que nadie se ha animado a responderte xD, trataré de ayudarte:
Código PHP:
    <?php
//Crea una funcion (con esto realizas una acción digamos encapsulada para luego darle uso más adelante.
    
function parse_rss($f) {
//con fopen abres un archivo, en este caso abre "read" la variable $f que supongo es el archivo.
        
$xmlfile fopen($f'r');
//Crea un if por si no puede.
        
if (!$xmlfile) die('cannot open the xml file');
//Lee el archivo abierto.
        
$readfile fread($xmlfile ,40000);
/
Busca coincidencias en lo que leeen este casi a partir de <item>(.*)</item>, más infohttp://www.php.net/eregi
        
$parsefile eregi("<item>(.*)</item>"$readfile ,$arrayreg);
//Hacer un explode para divir el cotenido y utilizarlo.
        
$filechunks explode("<item>"$arrayreg[0]);
//cuenta las divisiones
        
$count count($filechunks);
//imprimire, en este caso el el tipo de fuente para un futuro bucle.
        
echo '<font face=verdana><ul>';
//Inicia el bucle por el cual imprimira lo leeido y divido anteriormentee
        
for($i=$i<=$count-;$i++) {
            
ereg("<title>(.*)</title>",$filechunks[$i], $title);
            
ereg("<link>(.*)</link>",$filechunks[$i], $links);
            
ereg("<description>(.*)</description>",$filechunks[$i], $description);
            echo 
str_replace('hxaxh','a',"<li><font style='font-size: 12px;'><hxaxh target=_blank href ='$links[1]'\>".utf8_decode($title[1])."</hxaxh></font>");
            echo 
"<br><font color=gray style='font-size: 10px;'>".utf8_decode($description[1])."</font></li>";
        }
//Termina bucle e imprime otras cositas..
        // feel free to remove next notice
        // is not needed by this function
        
echo '</ul><font style="font-size: 10px;">Better News Grabber by ';
        echo 
str_replace('hxaxh','a','<hxaxh target=_blank href="http://mdnava.network.com.ve/">Melvin D. Nava</hxaxh></font></font></font>');
    }
    
//
    // The Example
    //
    
echo '<h1>Star Wars News</h1>';
    
$xmlfeed 'http://www.starwars.com/community/webmasters/starwars.rdf';
    
parse_rss($xmlfeed);
    
?>
Bueno, espero te ayude algo, algunas sentencias utilizadas:
fopen, fread, echo, explode, eregi o ereg, for(bucles while and if, etc), MAS INFO,

http://www.php.net/LASENTENCIA QUE BUSCAS.

un abrazo.
__________________
I do techy stuff for a living and practice MMA with my dog... He always wins.