Ver Mensaje Individual
  #1 (permalink)  
Antiguo 07/03/2014, 15:56
striderwar
 
Fecha de Ingreso: diciembre-2005
Ubicación: Jalisco
Mensajes: 31
Antigüedad: 18 años, 4 meses
Puntos: 0
Leer texto row por row.

hola,
Tengo un codigo que lee un csv. y quiero sustituir unos atrributos de un xml especificos.
El problema es que cada Row del csv.
Código:
1234,5678,0987,6564 <- Row 1
1234,5678,0987,6564 <- Row2
Cada vez que termine de leer el primer Row, se cree un xml.
y cuando termine el segundo se cree otro xml...
y asi hasta que termine de leer todos.

este es mi codigo.

Código PHP:
<?php

function csv_in_array($url,$delm=",",$encl="\"") {

$doc = new DOMDocument();
$xml2 "A2CBOT.xml";
$doc->load($xml2);  
$xp = new DOMXPath($doc);

    
$csvxrow file($url);   // ---- csv rows to array ----
    
    
$csvxrow[0] = chop($csvxrow[0]);
    
$csvxrow[0] = str_replace($encl,'',$csvxrow[0]);
    
$keydata explode($delm,$csvxrow[0]);
    
    
$anzdata count($csvxrow);
    
$z=0;
    for(
$x=1$x<$anzdata$x++) {
        
$csvxrow[$x] = chop($csvxrow[$x]);
        
$csvxrow[$x] = str_replace($encl,'',$csvxrow[$x]);
        
$csv_data[$x] = explode($delm,$csvxrow[$x]);
        
$i=0;
        
$a=0;
        foreach(
$keydata as $key) {
            
$out[$z][$key] = $csv_data[$x][$i];
            
$i++;
            
////// Aqui reemplazara los atributos 

               
foreach($xp->query('/ROOT/HEADER/@KEY[. != ""]') as $attrib)
               {
                
$attrib->nodeValue $out[$z][$key];
               }
               foreach(
$xp->query('/ROOT/DATA/SAPMES/LOIPRO/E1FKOL/@AUFNR[. != ""]') as $attrib)
               {
                
$attrib->nodeValue $out[$z][$key];
               }
               foreach(
$xp->query('/ROOT/DATA/SAPMES/LOIPRO/E1FKOL/@GAMNG[. != ""]') as $attrib)
               {
                
$attrib->nodeValue $out[$z][$key];
               }
               foreach(
$xp->query('/ROOT/DATA/SAPMES/LOIPRO/E1FKOL/@GSTRS[. != ""]') as $attrib)
               {
                
$attrib->nodeValue $out[$z][$key];
               }
               foreach(
$xp->query('/ROOT/DATA/SAPMES/LOIPRO/E1FKOL/@GLTRS[. != ""]') as $attrib)
               {
                    
                   
//$datesum = date($out[$z][$key],  strtotime('+1 month'));
                
$attrib->nodeValue $datesum;
               }
               foreach(
$xp->query('/ROOT/DATA/SAPMES/LOIPRO/E1AFFLL/E1FVOL/@MGVRG[. != ""]') as $attrib)
               { 
                 
$attrib->nodeValue $out[$z][$key];
                 }
            
//////

            
}
        
$z++;
        }
        
        
   echo 
$doc->saveXML(); 

return 
$out;
}

// --------------------------------------------------------------

?>

<?php

$csvdata 
csv_in_array("LISTOTA.csv"",""\"");
No encuentro la forma espero puedan ayudarme.

Gracias.