Magento 1.9 – Fix Parser Error ‘Start Tag Expected, ‘<' Not Found'

configurationmagento-1.9xml

I am getting these errors in system.log.

2017-06-20T11:59:55+00:00 ERR (3): Warning: simplexml_load_string(): Entity: line 1: parser error : Start tag expected, '&lt;' not found  in home/www/lib/Varien/Simplexml/Config.php on line 512
2017-06-20T11:59:55+00:00 ERR (3): Warning: simplexml_load_string():   in /home/www/lib/Varien/Simplexml/Config.php on line 512
2017-06-20T11:59:55+00:00 ERR (3): Warning: simplexml_load_string(): ^  in /home/www/lib/Varien/Simplexml/Config.php on line 512

I tried debugging them by adjusting the loadstring function in the config.php file:

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;
}

The response in the system.log is not pointing to any logic location or file. How to debug this:

2017-06-20T11:59:56+00:00 DEBUG (7): XML_ERROR: ’°#  .   ½; ô..                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
2017-06-20T11:59:57+00:00 DEBUG (7): XML_ERROR: <config/>

Changed the error login as sugested in the comments. This is what the response is now:

2017-06-20T12:43:51+00:00 ERR (3): Notice: Undefined variable: classblock  in /home/www/app/code/local/Cmsmart/Megamenu/Block/Navigation.php on line 186
2017-06-20T12:43:51+00:00 ERR (3): Notice: Undefined variable: nothumbnail  in /home/www/app/code/local/Cmsmart/Megamenu/Block/Navigation.php on line 84
2017-06-20T12:43:51+00:00 ERR (3): Notice: Undefined variable: classblock  in /home/www/app/code/local/Cmsmart/Megamenu/Block/Navigation.php on line 186
2017-06-20T12:43:51+00:00 DEBUG (7): LibXMLError Object
(
[level] => 3
[code] => 4
[column] => 1
[message] => Start tag expected, '<' not found

[file] => 
[line] => 1
)

2017-06-20T12:43:53+00:00 DEBUG (7): LibXMLError Object
(
[level] => 3
[code] => 4
[column] => 1
[message] => Start tag expected, '<' not found

[file] => 
[line] => 1
)

Got this error:

2017-06-20T14:19:51+00:00 DEBUG (7): LibXMLError Object
(
[level] => 3
[code] => 4
[column] => 1
[message] => Start tag expected, '<' not found

[file] => ./app/design/frontend/default/theme313k/layout/cmsmart
[line] => 1
)

This is the corresponding file contents. I don't see anything wrong with that file. Also tried to remove whitespaces etc.

<?xml version="1.0"?>
<layout version="0.1.0">
<default>
    <reference name="top.menu" >
          <action  method="unsetChild" ><name>catalog.topnav</name>     </action>
          <block type="page/html_topmenu" name="catalog.topnav2" template="page/html/topmenu_2.phtml"/>
           <block type="megamenu/navigation"  name="catalog.topnav.megamenu">
              <action method="unsetData"><key>cache_lifetime</key></action>
              <action method="unsetData"><key>cache_tags</key></action>
           </block>
    </reference>

</default>
</layout>

Best Answer

Please check your config.xml, system.xml and all the layout.xml files.

For debugging you can try this ... create file in magento root

<?php
require_once('./app/Mage.php');
umask(0);
Mage::app();

// enable user error handling
libxml_use_internal_errors(true);

// adjust template path
$dir = "./app/design/frontend/base/default/layout/*";

foreach(glob($dir) as $file) {
    $xml = simplexml_load_file($file);
    foreach (libxml_get_errors() as $error) {
        Mage::log($error);
    }
    libxml_clear_errors();
}

Output looks like

2017-06-20T13:28:21+00:00 DEBUG (7): Array
(
    [0] => ./app/design/frontend/base/default/layout/catalog.xml
    [1] => LibXMLError Object
        (
            [level] => 3
            [code] => 76
            [column] => 28
            [message] => Opening and ending tag mismatch: reference line 191 and catalog_product_view

            [file] => ./app/design/frontend/base/default/layout/catalog.xml
            [line] => 262
        )

)

Source: http://www.php.net/manual/en/function.libxml-use-internal-errors.php


Edit: check all XML files ...

<?php
require_once('./app/Mage.php');
umask(0);
Mage::app();

// enable user error handling
libxml_use_internal_errors(true);

$root = './app';
$iterator  = new RecursiveIteratorIterator(
    new RecursiveDirectoryIterator($root, RecursiveDirectoryIterator::SKIP_DOTS),
    RecursiveIteratorIterator::SELF_FIRST,
    RecursiveIteratorIterator::CATCH_GET_CHILD
);

foreach ($iterator as $path => $item) {
    if ($item->isFile() && $item->getExtension() == 'xml') {
        $xml = simplexml_load_file($path);
        foreach (libxml_get_errors() as $error) {
            Mage::log($error);
        }
        libxml_clear_errors();
    }
}
Related Topic