Magento system log 中出現: Warning: simplexml_load_string(): Entity: line 151: parser error

You are here:
  • Main
  • Magento
  • 除錯
  • Magento system log 中出現: Warning: simplexml_load_string(): Entity: line 151: parser error
< All Topics

在 Log Viewer 中不斷的看到同樣的錯誤訊息

2017-05-25T09:07:59+00:00 ERR (3): Warning: simplexml_load_string(): Entity: line 150: parser error : Opening and ending tag mismatch: config line 2 and resources in /usr/share/nginx/html/lib/Varien/Simplexml/Config.php on line 510
2017-05-25T09:07:59+00:00 ERR (3): Warning: simplexml_load_string(): &lt;/resources&gt; in /usr/share/nginx/html/lib/Varien/Simplexml/Config.php on line 510
2017-05-25T09:07:59+00:00 ERR (3): Warning: simplexml_load_string(): ^ in /usr/share/nginx/html/lib/Varien/Simplexml/Config.php on line 510

我們可以利用一些簡單的修改,讓 log 記錄錯誤的原因

 

編輯 /usr/share/nginx/html/lib/Varien/Simplexml/Config.php

vim /usr/share/nginx/html/lib/Varien/Simplexml/Config.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/**
 * 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;
}

修改為

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/**
 * 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;
}

之後就會將發生錯誤的檔案顯示在 system.log 之中囉

2017-05-26T08:07:52+00:00 DEBUG (7): XML_ERROR: <config/>
2017-05-26T08:07:55+00:00 DEBUG (7): XML_ERROR: <config/>
2017-05-26T08:08:01+00:00 DEBUG (7): XML_ERROR: <config/>
2017-05-26T08:08:04+00:00 DEBUG (7): XML_ERROR: <config/>
2017-05-26T08:09:54+00:00 DEBUG (7): XML_ERROR: <config/>
2017-05-26T08:10:53+00:00 DEBUG (7): XML_ERROR: <config/>
2017-05-26T08:14:30+00:00 DEBUG (7): XML_ERROR: <config/>
2017-05-26T08:14:36+00:00 DEBUG (7): XML_ERROR: <config/>
2017-05-26T08:14:40+00:00 DEBUG (7): XML_ERROR: <?xml version="1.0"?><jstranslator></jstranslator>
2017-05-26T08:15:43+00:00 DEBUG (7): XML_ERROR: <config/>
2017-05-26T08:15:43+00:00 ERR (3): Warning: simplexml_load_string(): Entity: line 150: parser error : Opening and ending tag mismatch: config line 2 and resources in /usr/share/nginx/html/lib/Varien/Simplexml/Config.php on line 510
2017-05-26T08:15:43+00:00 ERR (3): Warning: simplexml_load_string(): &lt;/resources&gt; in /usr/share/nginx/html/lib/Varien/Simplexml/Config.php on line 510
2017-05-26T08:15:43+00:00 ERR (3): Warning: simplexml_load_string(): ^ in /usr/share/nginx/html/lib/Varien/Simplexml/Config.php on line 510
2017-05-26T08:15:43+00:00 ERR (3): Warning: simplexml_load_string(): Entity: line 151: parser error : Extra content at the end of the document in /usr/share/nginx/html/lib/Varien/Simplexml/Config.php on line 510
2017-05-26T08:15:43+00:00 ERR (3): Warning: simplexml_load_string(): &lt;/acl&gt; in /usr/share/nginx/html/lib/Varien/Simplexml/Config.php on line 510
2017-05-26T08:15:43+00:00 ERR (3): Warning: simplexml_load_string(): ^ in /usr/share/nginx/html/lib/Varien/Simplexml/Config.php on line 510
2017-05-26T08:15:43+00:00 DEBUG (7): XML_ERROR: <?xml version="1.0"?>
<config>
 <modules>
 <Plumrocket_WhoBoughtThisAlsoBought>
 <wiki>http://wiki.plumrocket.com/wiki/Magento_Who_Bought_This_Also_Bought_v1.x_Extension</wiki>
 <version>1.0.1</version>
 </Plumrocket_WhoBoughtThisAlsoBought>
 </modules>

<frontend>
 <layout>
 <updates>
 <plwhobought>
 <file>plwhobought.xml</file>
 </plwhobought>
 </updates>
 </layout>
 <translate>
 <modules>
 <Plumrocket_WhoBoughtThisAlsoBought>
 <files>
 <default>Plumrocket_Whoboughtthisalsobought.csv</default>
 </files>
 </Plumrocket_WhoBoughtThisAlsoBought>
 </modules>
 </translate>
 </frontend>

<global>
 <helpers>
 <plwhobought>
 <class>Plumrocket_WhoBoughtThisAlsoBought_Helper</class>
 </plwhobought>
 </helpers>
 
 <blocks>
 <plwhobought>
 <class>Plumrocket_WhoBoughtThisAlsoBought_Block</class>
 </plwhobought>
 </blocks>
 
 <models>
 <plwhobought>
 <class>Plumrocket_WhoBoughtThisAlsoBought_Model</class>
 <resourceModel>plwhobought_mysql4</resourceModel>
 </plwhobought>
 <plwhobought_mysql4>
 <class>Plumrocket_WhoBoughtThisAlsoBought_Model_Mysql4</class>
 <entities>
 <plwhobought>
 <table>pl_who_bought</table>
 </plwhobought>
 <ordersdone>
 <table>pl_who_bought_orders_done</table>
 </ordersdone>
 </entities>
 </plwhobought_mysql4>
 </models>
 
 <events>
 <sales_order_save_after>
 <observers>
 <plwhobought_save_bought_products>
 <type>singleton</type>
 <class>plwhobought/observer</class>
 <method>saveBoughtProducts</method>
 </plwhobought_save_bought_products>
 </observers>
 </sales_order_save_after>
 </events>
 
 <resources>
 <plwhobought_setup>
 <setup>
 <module>Plumrocket_WhoBoughtThisAlsoBought</module>
 </setup>
 <connection>
 <use>core_setup</use>
 </connection>
 </plwhobought_setup>
 <plwhobought_write>
 <connection>
 <use>core_write</use>
 </connection>
 </plwhobought_write>
 <plwhobought_read>
 <connection>
 <use>core_read</use>
 </connection>
 </plwhobought_read>
 </resources> 
 </global>

<admin>
 <routers>
 <adminhtml>
 <args>
 <modules>
 <Plumrocket_WhoBoughtThisAlsoBought_Adminhtml after="Mage_Adminhtml">Plumrocket_WhoBoughtThisAlsoBought_Adminhtml</Plumrocket_WhoBoughtThisAlsoBought_Adminhtml>
 </modules>
 </args>
 </adminhtml>
 </routers>
 </admin>

<!-- <adminhtml>
 <menu>
 <plumrocket>
 <title>Plumrocket</title>
 <sort_order>80</sort_order>
 <children>
 <plwhobought>
 <title>Who Bought This Also Bought</title>
 <action>adminhtml/system_config/edit/section/plwhobought</action>
 <sort_order>3000</sort_order>
 </plwhobought>
 </children>
 </plumrocket>
 </menu>
 <acl>
 <resources>
 <all>
 <title>Allow Everything</title>
 </all>
 <admin>
 <children>
 <plumrocket>
 <title>Plumrocket</title>
 <sort_order>80</sort_order>
 <children>
 <plwhobought translate="title">
 <title>Who Bought This Also Bought</title>
 <sort_order>3000</sort_order>
 </plwhobought>
 </children>
 </plumrocket>
 <system>
 <children>
 <config>
 <children>
 <plwhobought translate="title">
 <title>Who Bought This Also Bought Settings</title>
 </plwhobought>
 </children>
 </config>
 </children>
 </system>
 </children>
 </admin>-->
 </resources>
 </acl>
 </adminhtml>

<default>
 <plwhobought>
 <general>
 <orders_status>processing,pending,complete</orders_status>
 <same_store>1</same_store>
 </general>
 <display_settings>
 <product_page>page</product_page>
 <cart_page>page</cart_page>
 <number_products>5</number_products>
 </display_settings>
 </plwhobought>
 </default>

</config>

2017-05-26T08:15:44+00:00 DEBUG (7): XML_ERROR: <theme />
2017-05-26T08:15:45+00:00 DEBUG (7): XML_ERROR: <?xml version="1.0"?><config></config>
2017-05-26T08:15:46+00:00 DEBUG (7): XML_ERROR: <?xml version="1.0"?><jstranslator></jstranslator>

如上方的 log,可以看出 Plumrocket_WhoBoughtThisAlsoBought 這個模組的 xml 檔內容有錯誤,前去檢查除錯即可

 

因為更新 config.php 後,新出現的 DEBUG 部分有

2017-05-26T08:24:44+00:00 DEBUG (7): XML_ERROR: <config/>
2017-05-26T08:24:44+00:00 DEBUG (7): XML_ERROR: <theme />
2017-05-26T08:24:45+00:00 DEBUG (7): XML_ERROR: <?xml version="1.0"?><jstranslator></jstranslator>
2017-05-26T08:24:45+00:00 DEBUG (7): XML_ERROR: <?xml version="1.0"?><config></config>

只需要將 config.php 還原,就不會再出現了

 

參考資料:

Magento: solve XML parsing issues

Magento – tons of debug in system.log, how do I debug?

 

Previous Magento Bundle Product 於 JavaScript 控制台顯示錯誤
Next Magento、Ultimo Bug 除錯、修改大集合
Table of Contents