Magento: Warning: simplexml_load_string(): Entity: line 1: parser error

A co-worker of mine was working on a Magento site and ran into the following error:

Warning: simplexml_load_string(): Entity: line 1: parser error : XML declaration allowed only at the start of the document in /.../.../.../.../app/code/core/Mage/Core/Model/Layout/Update.php on line 431

I’ve seen this before, but didn’t remember exactly what to look for. So, here’s what I did to solve his issue, and hopefully this ends up helping you:

Open up app/code/core/Mage/Core/Model/Layout/Update.php and go down to line 431 where the error is occurring. Right before that line, insert a new line:

Mage::log(print_r($filename, true));

Make sure your logging is turned on, then refresh the page in your browser. It will end up spitting out a bunch of layout files in your var/log/system.log. The last layout xml file on the list should be your culprit. In my case, there were 4 spaces in front of the xml declaration in the last file on the list. So, I removed the spaces, and everything worked fine.

Don’t forget to remove the line you put in Update.php when you are done!

This entry was posted in Magento. Bookmark the permalink.

4 Responses to Magento: Warning: simplexml_load_string(): Entity: line 1: parser error

  1. Ardi says:

    Hello, I need some help with it. When I try to go to magento front page it pops up this:
    “Warning: simplexml_load_string(): Entity: line 2: parser error : Comment not terminated.”
    Nothing is shown in system.log about this as well. I don’t know where to put “Mage::log(print_r($filename, true));” to help me find this error.
    Help please.

    • Ardi says:

      Found a solution. Used this command:
      $ xmllint * | grep error
      in magento’s layout directory, which pointed me to payment.xml. It said “payment.xml:26: parser error : Start tag expected, ‘” It was expecting something…but everything had been commented before with an update to 1.7 so I uncommented the xml … and everything works again.

  2. fil says:

    Wow awesome! This taught me something new and AND helped me fix my problem. Thank you for this post!

  3. Denisa says:

    Thank you very much! I found my issue because of you :)