如何轻松调试布局Xml警告/错误? [英] How to easily Debug Layout Xml Warning/Error?

查看:99
本文介绍了如何轻松调试布局Xml警告/错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到这个错误:

Warning: simplexml_load_string(): Entity: line 46: parser error : Comment not terminated  in */lib/Varien/Simplexml/Config.php on line 510

Entity: line 46: parser error : Start tag expected, '<' not found  in */lib/Varien/Simplexml/Config.php on line 510

很明显,在一些Xml文件中有一个问题,但真的没有容易让我在大干草堆中找到针:)

It is clear that there is an issue in some Xml file, but really not easy for me to find out the needle in the big haystack :)

有什么好的做法吗?
如果可能,我想找到一个很好的做法,涉及使用Xdebug或一些日志。

Any good practice for that? If possible I would like to find a good practice that involves use Xdebug, or some log.

在Magento做了一些错误发生了很多时间拼写。

It happens a lot of time in Magento to do some miss spelling.

推荐答案

我想你可以看看这篇文章处理XML错误

I think you can take a look at this article Dealing with XML errors.

此警告与某些config.xml错误相关,所以一个可能的解决方法找出确切的文件是mod。 /lib/Varien/Simplexml/Config.php类。

This warning is related to some config.xml error, so a possible workaround to find out the exact file is to mod. the /lib/Varien/Simplexml/Config.php class.

您应该修改 Varien_Simplexml_Config :: loadString()方法:

    public function loadString($string)
    {
        if (is_string($string)) {
            // Enable internal errors
            libxml_use_internal_errors(true);
            $xml = simplexml_load_string($string, $this->_elementClass);
            if (false === $xml) {
                // Put breakpoint here
                $errors = libxml_get_errors();
            }
            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;
    }

如果错误与某些布局文件相关(Update.php line 444警告)

In case the error is related to some Layout file ( Update.php line 444 warning )

您应该以类似的方式修改 Mage_Core_Model_Layout_Update :: getFileLayoutUpdatesXml()方法:

You should modify Mage_Core_Model_Layout_Update::getFileLayoutUpdatesXml() method in a similar way:

  public function getFileLayoutUpdatesXml($area, $package, $theme, $storeId = null)
{
    if (null === $storeId) {
        $storeId = Mage::app()->getStore()->getId();
    }
    /* @var $design Mage_Core_Model_Design_Package */
    $design = Mage::getSingleton('core/design_package');
    $layoutXml = null;
    $elementClass = $this->getElementClass();
    $updatesRoot = Mage::app()->getConfig()->getNode($area.'/layout/updates');
    Mage::dispatchEvent('core_layout_update_updates_get_after', array('updates' => $updatesRoot));
    $updateFiles = array();
    foreach ($updatesRoot->children() as $updateNode) {
        if ($updateNode->file) {
            $module = $updateNode->getAttribute('module');
            if ($module && Mage::getStoreConfigFlag('advanced/modules_disable_output/' . $module, $storeId)) {
                continue;
            }
            $updateFiles[] = (string)$updateNode->file;
        }
    }
    // custom local layout updates file - load always last
    $updateFiles[] = 'local.xml';
    $layoutStr = '';
    foreach ($updateFiles as $file) {
        $filename = $design->getLayoutFilename($file, array(
            '_area'    => $area,
            '_package' => $package,
            '_theme'   => $theme
        ));
        if (!is_readable($filename)) {
            continue;
        }
        $fileStr = file_get_contents($filename);
        $fileStr = str_replace($this->_subst['from'], $this->_subst['to'], $fileStr);   


        libxml_use_internal_errors(true);
        $fileXml = simplexml_load_string($fileStr, $elementClass);


        if (false === $fileXml) {
            // Put breakpoint here
            $errors = libxml_get_errors();
            $err = array($filename, $errors);
            // error detail and file name will be printed
            Zend_Debug::dump($err);
            die();
        }



        if (!$fileXml instanceof SimpleXMLElement) {
            continue;
        }
        $layoutStr .= $fileXml->innerXml();
    }
    $layoutXml = simplexml_load_string('<layouts>'.$layoutStr.'</layouts>', $elementClass);
    return $layoutXml;
}

现在只需重新加载页面即可阅读错误信息。

Now just reload the page a read the error info.

这篇关于如何轻松调试布局Xml警告/错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆