Ver Mensaje Individual
  #5 (permalink)  
Antiguo 06/09/2009, 15:41
Avatar de neodani
neodani
 
Fecha de Ingreso: marzo-2007
Mensajes: 1.811
Antigüedad: 17 años, 2 meses
Puntos: 20
Respuesta: Problema simpleXML

He conseguido mostrar los datos del XML en formato array

Código php:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <title>Analizar XML</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. </head>
  7. <body>
  8. <?php
  9.  
  10.  class xml {
  11.    
  12.     var $matriz = array();
  13.     var $resultado;
  14.     var $informacion;
  15.    
  16.     function xml($contenido) {
  17.    
  18.             $this->resultado = xml_parser_create ();
  19.             xml_set_object($this->resultado,$this);
  20.             xml_set_element_handler($this->resultado, "abrir", "cerrar");
  21.            
  22.             xml_set_character_data_handler($this->resultado, "info");
  23.        
  24.             $this->informacion = xml_parse($this->resultado,$contenido);
  25.                          
  26.             xml_parser_free($this->resultado);
  27.            
  28.             return $this->matriz;
  29.     }
  30.     function abrir($parser, $nombre, $atributos) {
  31.         $etiqueta = array("nombre"=>$nombre,"atributos"=>$atributos);
  32.         array_push($this->matriz,$etiqueta);
  33.     }
  34.    
  35.     function info($parser, $etiqueta_info) {
  36.         if(trim($etiqueta_info)) {
  37.             if(isset($this->matriz[count($this->matriz)-1]['info'])) {
  38.                $this->matriz[count($this->matriz)-1]['info'] .= $etiqueta_info;
  39.             }
  40.             else {
  41.                $this->matriz[count($this->matriz)-1]['info'] = $etiqueta_info;
  42.             }
  43.         }
  44.     }
  45.    
  46.     function cerrar($parser, $nombre) {
  47.        $this->matriz[count($this->matriz)-2]['hijo'][] = $this->matriz[count($this->matriz)-1];
  48.         array_pop($this->matriz);
  49.     }
  50.  }
  51.  
  52. $url = "http://partnerfeed.itsfogo.com/partnerfeed.aspx?partnerfeedID=1305&ZoneID=34296&partnerTargetLink=&partnerField=itsfogoTargetLink";
  53. $xml_contenido = file_get_contents($url,'r');
  54.  
  55. $xml = new xml($xml_contenido);
  56.  
  57. echo '<pre>';
  58. print_r($xml->matriz);
  59. echo '</pre>';
  60.  
  61. ?>
  62.  
  63.  
  64. </body>
  65. </html>

Ahora me falta acceder a cada una de las posiciones y guardar los datos en un base de datos mysql.

¿Alguna sugerencia?

Gracias