İki hataları zaman PHP xmlReader kullanarak

1 Cevap php

XMLReader kullanırken aşağıdaki iki hata var.

1) Uyarı: XMLReader :: read () [xmlreader.read]: MyXML.xml: 43102: ayrıştırıcı hatası: xmlParseEntityRef: hayır isim

2) Uyarı: XMLReader :: read () [xmlreader.read]: ^ MyXMLReader.php line 56

Herkes bu bakın ne biliyor mu?

Benim PHP Kodu (XML dosyası 100MB hakkında bu yüzden içeremez):

<?php 

//Assign file names
$XMLFile = 'MyXML.xml';
$CSVFile = 'MyCSV.csv';

//take start time to calculate run-time
$time_start = time();

//Open PHP's XMLReader.  XMLReader opens each element in the XML one by one to keep memory use small.
$xml = new XMLReader(); 
$xml->open($XMLFile, null, 1<<19); 

//Loop through all elements.  Save all text from tags and attributes.
while ($xml->read()) {

    if($xml->nodeType == XMLReader::TEXT) { 
        $row[$xml->name] = $xml->value;
    }

    if($xml->hasAttributes)  {
        while($xml->moveToNextAttribute()) { 
            $row[$xml->name] = $xml->value;
        }
    }
}

//save the titles which should appear in CSV file.  All others will not be included.
$SavedRows = $row;
unset($row);

//Remove unnecessary columns i.e. datasource URLs
$RemoveColumn='xmlns:message, xmlns:common, xmlns:frb, xmlns:xsi, xsi:schemaLocation, xmlns:kf';
$RemoveColumns = explode(',', $RemoveColumn);

foreach($RemoveColumns as $key => $val) {
    $val = trim($val);
    unset($SavedRows[$val]);
}

//initiate all rows which should be included
foreach($SavedRows as $key => $val) {
    $row[$key] = '';
}

//Create csv file
$fp = fopen($CSVFile, 'w');

//Input the column headings as first row
fputcsv($fp, array_keys($row), ',');

// Start 2nd loop through XML.
$xml = new XMLReader(); 
$xml->open($XMLFile, null, 1<<19); 

while ($xml->read()) {

    //Determine if tag is empty (An empty tag will contain data) Non empty tags contain series information.
    $Output = $xml->isEmptyElement;

    //Take data from non empty XML tags
    if($xml->nodeType == XMLReader::TEXT) { 
        if(isset($SavedRows[$xml->name])) {
            $row[$xml->name] = $xml->value;
        }
    }

    //take data from XML tag attributes
    if($xml->hasAttributes)  {
        while($xml->moveToNextAttribute()) { 
            if(isset($SavedRows[$xml->name])) {
                $row[$xml->name] = $xml->value;
            }
        }
    }

    //If tag is empty, assume it is data and write row to file.
    if($Output) {
        fputcsv($fp, array_values($row), ',');
    }

}

//Close file handle
fclose($fp);

//Calculate runtime
$time_end = time();
$time = $time_end - $time_start;

 echo "Complete.  Runtime: $time seconds";

 ?>

1 Cevap

xmlParseEntityRef: no name 

Eğer XML dosyasında sahte çıkmamış ve işaretleri var demektir. (Eh, "XML" ... iyi biçimlendirilmiş değil teknik olarak, eğer XML değildir.)

Sen onları kaçmak için yalnız & s için dosyayı kontrol edin (ya da oluşturulan kodu düzeltmek) gerekir &amp;. Hata göre, ilk dosyaya (yikes!) hattı 43102 üzerinde bulunuyor.