Ver Mensaje Individual
  #1 (permalink)  
Antiguo 10/01/2006, 20:09
sintesk7
 
Fecha de Ingreso: agosto-2004
Mensajes: 349
Antigüedad: 19 años, 7 meses
Puntos: 3
error con parseo de xml

Hola a todos!

me bajé un script para generar instrucciones INSERT (de mysql) a partir de un documento xml, para así convertir xml a mysql.

el problema es que solo me devuelve el último "registro"

dejo aqui el script:

Código PHP:
<?php
$file 
"http://www.infomallorca.net/xml/hoy/hoy_rss.ct.html";
$feed = array();
$key "";
$info "";

function 
startElement($xml_parser,  $attrs ) {
  global 
$feed;
   }

function 
endElement($xml_parser$name) {
  global 
$feed,  $info;
   
$key $name;
  
$feed[$key] = $info;
  
$info ""; }

function 
charData($xml_parser$data ) {
  global 
$info;
  
$info .= $data; }

$xml_parser xml_parser_create();
xml_set_element_handler($xml_parser"startElement""endElement");
xml_set_character_data_handler($xml_parser"charData" );
$fp fopen($file"r");
while (
$data fread($fp8192))
!
xml_parse($xml_parser$datafeof($fp));
xml_parser_free($xml_parser);

$sql"INSERT INTO `article` ( `";
$j=0;
$i=count($feed);
foreach( 
$feed as $assoc_index => $value )
  {
  
$j++;
  
$sql.= strtolower($assoc_index);
  if(
$i>$j$sql.= "` , `";
  if(
$i<=$j) {$sql.= "` ) VALUES ('";}
  }
 
$h=0;
foreach( 
$feed as $assoc_index => $value )
  {
  
$h++;
  
$sql.= utf8_decode(trim(addslashes($value)));
  if(
$i-1>$h$sql.= "', '";
  if(
$i<=$h$sql.= "','')";
  }
  
$sql=trim($sql);
  echo 
$sql;

?>
me gusaría que pudiese obtener la "tabla" con todos los registros