Magento Warning: simplexml_load_string() Parser Error

By | December 7, 2013

I recently came across a complex problem in a Magento installation that was quite a challenge to debug.  An installation was no longer sending out Shipping emails and I was seeing this set of errors in the Magento system.log file:

ERR (3): Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 43: parser error : Opening and ending tag mismatch: monkey line 43 and groupings in /chroot/home/html/lib/Varien/Simplexml/Config.php on line 383
ERR (3): Warning: simplexml_load_string() [function.simplexml-load-string]: k_frequency><385e246c53>4481 in /chroot/home/html/lib/Varien/Simplexml/Config.php on line 383
ERR (3): Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in /chroot/home/html/lib/Varien/Simplexml/Config.php on line 383
ERR (3): Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 43: parser error : Opening and ending tag mismatch: default line 4 and monkey in /chroot/home/html/lib/Varien/Simplexml/Config.php on line 383
ERR (3): Warning: simplexml_load_string() [function.simplexml-load-string]: cy><385e246c53>4481 in /chroot/home/html/lib/Varien/Simplexml/Config.php on line 383

My first thought was this was caused by an error in an XML file installed by an extension. Using the information in the log file I was able to track down the specific XML file that was reported. The weird thing was the XML in the file had no error. It was well formed without any problems. But then why was the system finding an error? Other sources I talked to said it had to be a problem in the XML. I had gone through all the XML using a validity tool and was confident that wasn’t the problem. I had to go deeper into the problem and in another direction.

After doing some reading, I started thinking the issue might be with the Config cache created in Magento’s cache management. That was easy to test. I turned off the Config cache, cleared the cache and the problem went away. The problem had to be with Config cache process. Others I contacted said it was probably an issue in simplexml config.php file itself (located at lib/Varien/Simplexml/Config.php). This is the php file that creates the cache. I checked the simplexml config.php file. It was the original file and comparing it to a backup, it was in its original condition. So that wasn’t the problem.

When the Config cache is enabled in Magento, it takes all the config.xml files and combines them into one big file in the cache. That shouldn’t be a problem because I had already validated the XML. In the system.log I saw error references to an extension that had been removed. How could that be? The XML for that extension was removed? Then I had an ah-ha moment.

The Config cache not only uses XML files it also uses the fields in the SQL table core_config_data and builds XML from that as well. Using phpadmin I looked into the core_config_data table. Sure enough, there were entries for the deleted extensions. Leftovers. Since I knew the problem was in the cached Config file, I took it and used an XML validator on it. That helped me zero in on the problem. An XML element that started with a number! It was coming from the core_config_data table. I found the entry in the table and determined it was an old entry from an old version of an extension.

The extension had taken an external value that would normally start with a letter but could on rare occasions start a number and created a name in the table /groupings/385e246c53 with a value of 4481. When the cache was created it built an XML entry: 4481. This was the cause of my error. You can see it in the original error report. If I knew then what I know now, I would have seen that error record, not found it in the XML file, and immediately known the cause of the error. The cache file. Now you know.

I determined the entry wasn’t used any more by comparing the entries to other installations. This entry didn’t exist in any of them. So I backed up the database and deleted the entry. When I created the Config cache, the problem went away. It felt great.

While this type of issue should be very rare, it is exactly that trait that makes it difficult to find. Hopefully this article helps. Let me know in the comments below if it does!

Leave a Reply

Your email address will not be published. Required fields are marked *