simplexml_load_string(): Entity: line 1: parser error : Attribute type redefined in Excel2007.php on line 1314

Topics: User Forum
Mar 2, 2015 at 7:51 PM
Line 1314:

$vmlCommentsFile = simplexml_load_string( $this->_getFromZipArchive($zip, $relPath) , 'SimpleXMLElement', PHPExcel_Settings::getLibXmlLoaderOptions());

The call to simplexml_load_string returns an empty string, so the next line:

$vmlCommentsFile->registerXPathNamespace('v', 'urn:schemas-microsoft-com:vml');

Should be where the error gets thrown. So I modified it so that we test $vmlCommentsFile to see if it is empty, which it is in this case, and if so sip the rest of the foreach loop:

This:
$vmlCommentsFile = simplexml_load_string( $this->_getFromZipArchive($zip, $relPath) , 'SimpleXMLElement', PHPExcel_Settings::getLibXmlLoaderOptions());
$vmlCommentsFile->registerXPathNamespace('v', 'urn:schemas-microsoft-com:vml'); 
Becomes this:
$vmlCommentsFile = simplexml_load_string( $this->_getFromZipArchive($zip, $relPath) , 'SimpleXMLElement', PHPExcel_Settings::getLibXmlLoaderOptions());
if(!empty($vmlCommentsFile))
    continue;
$vmlCommentsFile->registerXPathNamespace('v', 'urn:schemas-microsoft-com:vml'); 
And the error no longer happens and I'm able to process my spreadsheet.

But the real question is, why? Is this an omission (read:bug) in the code, or is the spreadsheet I'm reading corrupted?
Coordinator
Mar 2, 2015 at 8:22 PM
Where does the spreadsheet come from? Is it generated by MS Excel itself?
Mar 2, 2015 at 8:44 PM
It is sent to us by one of our customers. My guess is that they use Excel to generate it but I couldn't say what version. I get the file second hand, I don't even have a directly line to the person that prepares it. It is an .xlsx file, fwiw.
Mar 2, 2015 at 8:52 PM
FWIW I'm using PHP 5.6.6 on Linux. I get several dozen spreadsheets every day from different sources, and they all get processed the same way. It is just this one spreadsheet from this one source that causes this problem. All of the other spreadsheets work fine.