We allways recomend using Magento's log tool to watch out and fix possible errors.
To enable it go to:
System > Configure
In the left menú we go to ADVANCED > Developer
We are interested in the option "Log configuration" that we must enable. Default log files are system.log and exception.log
With errors logs enabled our Magento will start to insert any error ocurred into the files:
var/log/system.log
and
var /log/exception.log
A common error is to find in system.log errors like:
Warning: simplexml_load_string(): Entity: line 1: parser error : XML declaration allowed only at the start of the document in /var/www/DOMAIN/httpdocs/lib/Varien/Simplexml/Config.php on line 510
The error tells us that something went wrong trying to parse an XML file. The problem is that we don't know which file is generating that error. This kind of errors can hugely increase the size of our system.log file. Ours was around 140MB!
The error is generated in the line 510 inside the file:
lib/Varien/Simplexml/Config.php
Around that line we found the loadString function defined as:
/** * Imports XML string * * @param string $string * @return boolean */ public function loadString($string) { if (is_string($string)) { $xml = simplexml_load_string($string, $this->_elementClass); if ($xml instanceof Varien_Simplexml_Element) { $this->_xml = $xml; return true; } } else { Mage::logException(new Exception('"$string" parameter for simplexml_load_string is not a string')); } return false; }
to obtain further details about the error we are going to modify that function to:
/** * Imports XML string * * @param string $string * @return boolean */ public function loadString($string) { if (is_string($string)) { $xml = simplexml_load_string($string, $this->_elementClass); if(!$xml){ Mage::log('XML_ERROR: ' . $string); } if ($xml instanceof Varien_Simplexml_Element) { $this->_xml = $xml; return true; } } else { Mage::logException(new Exception('"$string" parameter for simplexml_load_string is not a string')); } return false; }
We just asked Magento to log the failing XML string so we can search it in our files.
We recommend to delete the system.log file to force Magento to regenerate it. This way Magento will only show errors generated by te the modified function.
Now we simply refresh and navigate through our page to get/generate some errors in our system.log file.
And then we reopen our system.log and search for the string "XML_ERROR" that we inserted before any failing string. In our system the error was caused by some empty spaces inserted just before XML file declaration:
<?xml version="1.0" encoding="UTF-8"?>
we removed the empty spaces and no more errors were logged.
After the changes we can restore the original loadString function or just keep it to track future errors.