XML解析错误


10

我相信我有语法错误或什么?我相信这与xml或语法有关。当我查看文件时,一切似乎都井然有序。这个错误正在处理法师通知模块,对吗?问题是我看不到任何损坏的代码,例如:<!DOCTYPE HTML PUBLIC“-// IETF // DTD HTML 2.0 // EN”>

2017-11-16T23:12:24+00:00 ERR (3): Warning: SimpleXMLElement::__construct(): Entity: line 1: parser error : Space required after the Public Identifier  in /var/www/code/www.oop.com/releases/20171116222810/public_html/app/code/local/Magestore/Magenotification/Model/Magenotification.php on line 126
    2017-11-16T23:12:24+00:00 ERR (3): Warning: SimpleXMLElement::__construct(): &lt;!DOCTYPE HTML PUBLIC &quot;-//IETF//DTD HTML 2.0//EN&quot;&gt;  in /var/www/code/www.oop.com/releases/20171116222810/public_html/app/code/local/Magestore/Magenotification/Model/Magenotification.php on line 126
    2017-11-16T23:12:24+00:00 ERR (3): Warning: SimpleXMLElement::__construct():                                                  ^  in /var/www/code/www.oop.com/releases/20171116222810/public_html/app/code/local/Magestore/Magenotification/Model/Magenotification.php on line 126
    2017-11-16T23:12:24+00:00 ERR (3): Warning: SimpleXMLElement::__construct(): Entity: line 1: parser error : SystemLiteral &quot; or ' expected  in /var/www/code/www.oop.com/releases/20171116222810/public_html/app/code/local/Magestore/Magenotification/Model/Magenotification.php on line 126
    2017-11-16T23:12:24+00:00 ERR (3): Warning: SimpleXMLElement::__construct(): &lt;!DOCTYPE HTML PUBLIC &quot;-//IETF//DTD HTML 2.0//EN&quot;&gt;  in /var/www/code/www.oop.com/releases/20171116222810/public_html/app/code/local/Magestore/Magenotification/Model/Magenotification.php on line 126
    2017-11-16T23:12:24+00:00 ERR (3): Warning: SimpleXMLElement::__construct():                                                  ^  in /var/www/code/www.oop.com/releases/20171116222810/public_html/app/code/local/Magestore/Magenotification/Model/Magenotification.php on line 126
    2017-11-16T23:12:24+00:00 ERR (3): Warning: SimpleXMLElement::__construct(): Entity: line 1: parser error : SYSTEM or PUBLIC, the URI is missing  in /var/www/code/www.oop.com/releases/20171116222810/public_html/app/code/local/Magestore/Magenotification/Model/Magenotification.php on line 126
    2017-11-16T23:12:24+00:00 ERR (3): Warning: SimpleXMLElement::__construct(): &lt;!DOCTYPE HTML PUBLIC &quot;-//IETF//DTD HTML 2.0//EN&quot;&gt;  in /var/www/code/www.oop.com/releases/20171116222810/public_html/app/code/local/Magestore/Magenotification/Model/Magenotification.php on line 126
    2017-11-16T23:12:24+00:00 ERR (3): Warning: SimpleXMLElement::__construct():                                                  ^  in /var/www/code/www.oop.com/releases/20171116222810/public_html/app/code/local/Magestore/Magenotification/Model/Magenotification.php on line 126
    2017-11-16T23:12:24+00:00 ERR (3): Warning: SimpleXMLElement::__construct(): Entity: line 9: parser error : Opening and ending tag mismatch: hr line 7 and body  in /var/www/code/www.oop.com/releases/20171116222810/public_html/app/code/local/Magestore/Magenotification/Model/Magenotification.php on line 126
    2017-11-16T23:12:24+00:00 ERR (3): Warning: SimpleXMLElement::__construct(): &lt;/body&gt;&lt;/html&gt;  in /var/www/code/www.oop.com/releases/20171116222810/public_html/app/code/local/Magestore/Magenotification/Model/Magenotification.php on line 126
    2017-11-16T23:12:24+00:00 ERR (3): Warning: SimpleXMLElement::__construct():        ^  in /var/www/code/www.oop.com/releases/20171116222810/public_html/app/code/local/Magestore/Magenotification/Model/Magenotification.php on line 126
    2017-11-16T23:12:24+00:00 ERR (3): Warning: SimpleXMLElement::__construct(): Entity: line 9: parser error : Opening and ending tag mismatch: body line 4 and html  in /var/www/code/www.oop.com/releases/20171116222810/public_html/app/code/local/Magestore/Magenotification/Model/Magenotification.php on line 126
    2017-11-16T23:12:24+00:00 ERR (3): Warning: SimpleXMLElement::__construct(): Entity: line 9: parser error : Premature end of data in tag html line 2  in /var/www/code/www.oop.com/releases/20171116222810/public_html/app/code/local/Magestore/Magenotification/Model/Magenotification.php on line 126
    2017-11-16T23:12:24+00:00 ERR (3): Warning: SimpleXMLElement::__construct(): Entity: line 1: parser error : Space required after the Public Identifier  in /var/www/code/www.oop.com/releases/20171116222810/public_html/app/code/local/Magestore/Magenotification/Model/Magenotification.php on line 126
    2017-11-16T23:12:24+00:00 ERR (3): Warning: SimpleXMLElement::__construct(): &lt;!DOCTYPE HTML PUBLIC &quot;-//IETF//DTD HTML 2.0//EN&quot;&gt;  in /var/www/code/www.oop.com/releases/20171116222810/public_html/app/code/local/Magestore/Magenotification/Model/Magenotification.php on line 126
    2017-11-16T23:12:24+00:00 ERR (3): Warning: SimpleXMLElement::__construct():                                                  ^  in /var/www/code/www.oop.com/releases/20171116222810/public_html/app/code/local/Magestore/Magenotification/Model/Magenotification.php on line 126
    2017-11-16T23:12:24+00:00 ERR (3): Warning: SimpleXMLElement::__construct(): Entity: line 1: parser error : SystemLiteral &quot; or ' expected  in /var/www/code/www.oop.com/releases/20171116222810/public_html/app/code/local/Magestore/Magenotification/Model/Magenotification.php on line 126
    2017-11-16T23:12:24+00:00 ERR (3): Warning: SimpleXMLElement::__construct(): &lt;!DOCTYPE HTML PUBLIC &quot;-//IETF//DTD HTML 2.0//EN&quot;&gt;  in /var/www/code/www.oop.com/releases/20171116222810/public_html/app/code/local/Magestore/Magenotification/Model/Magenotification.php on line 126
    2017-11-16T23:12:24+00:00 ERR (3): Warning: SimpleXMLElement::__construct():                                                  ^  in /var/www/code/www.oop.com/releases/20171116222810/public_html/app/code/local/Magestore/Magenotification/Model/Magenotification.php on line 126
    2017-11-16T23:12:24+00:00 ERR (3): Warning: SimpleXMLElement::__construct(): Entity: line 1: parser error : SYSTEM or PUBLIC, the URI is missing  in /var/www/code/www.oop.com/releases/20171116222810/public_html/app/code/local/Magestore/Magenotification/Model/Magenotification.php on line 126
    2017-11-16T23:12:24+00:00 ERR (3): Warning: SimpleXMLElement::__construct(): &lt;!DOCTYPE HTML PUBLIC &quot;-//IETF//DTD HTML 2.0//EN&quot;&gt;  in /var/www/code/www.oop.com/releases/20171116222810/public_html/app/code/local/Magestore/Magenotification/Model/Magenotification.php on line 126
    2017-11-16T23:12:24+00:00 ERR (3): Warning: SimpleXMLElement::__construct():                                                  ^  in /var/www/code/www.oop.com/releases/20171116222810/public_html/app/code/local/Magestore/Magenotification/Model/Magenotification.php on line 126
    2017-11-16T23:12:24+00:00 ERR (3): Warning: SimpleXMLElement::__construct(): Entity: line 9: parser error : Opening and ending tag mismatch: hr line 7 and body  in /var/www/code/www.oop.com/releases/20171116222810/public_html/app/code/local/Magestore/Magenotification/Model/Magenotification.php on line 126
    2017-11-16T23:12:24+00:00 ERR (3): Warning: SimpleXMLElement::__construct(): &lt;/body&gt;&lt;/html&gt;  in /var/www/code/www.oop.com/releases/20171116222810/public_html/app/code/local/Magestore/Magenotification/Model/Magenotification.php on line 126
    2017-11-16T23:12:24+00:00 ERR (3): Warning: SimpleXMLElement::__construct():        ^  in /var/www/code/www.oop.com/releases/20171116222810/public_html/app/code/local/Magestore/Magenotification/Model/Magenotification.php on line 126
    2017-11-16T23:12:24+00:00 ERR (3): Warning: SimpleXMLElement::__construct(): Entity: line 9: parser error : Opening and ending tag mismatch: body line 4 and html  in /var/www/code/www.oop.com/releases/20171116222810/public_html/app/code/local/Magestore/Magenotification/Model/Magenotification.php on line 126
    2017-11-16T23:12:24+00:00 ERR (3): Warning: SimpleXMLElement::__construct(): Entity: line 9: parser error : Premature end of data in tag html line 2  in /var/www/code/www.oop.com/releases/20171116222810/public_html/app/code/local/Magestore/Magenotification/Model/Magenotification.php on line 126
    2017-11-16T23:12:34+00:00 ERR (3): Warning: SimpleXMLElement::__construct(): Entity: line 1: parser error : Space required after the Public Identifier  in /var/www/code/www.oop.com/releases/20171116222810/public_html/app/code/local/Magestore/Magenotification/Model/Magenotification.php on line 126

这是Magenotification.php中的126行

   try {
            $xml = new SimpleXMLElement($data);
        }

一点也帮不了我。

Magenotification.php

class Magestore_Magenotification_Model_Magenotification extends Mage_Core_Model_Abstract
{
    const XML_FREQUENCY_PATH    = 'magenotification/general/frequency';
    const XML_LAST_UPDATE_PATH  = 'magenotification/general/last_update';
    const XML_MAGESTORE_URL_PATH  = 'magenotification/general/magestore_url';

    public function _construct()
    {
        parent::_construct();
        $this->_init('magenotification/magenotification');
    }   

    public function checkUpdate()
    {
        $timestamp = Mage::getModel('core/date')->timestamp(time());

        if (($this->getFrequency() + $this->getLastUpdate()) > $timestamp) 
        {
            return $this;
        }

        $notificationXml = $this->getNotificationData();
        $noticeData = array();
        if ($notificationXml && $notificationXml->item) 
        {
            foreach ($notificationXml->item as $item) {
                    $item_data = array(
                        'severity'      => (int)$item->severity,
                        'date_added'    => $this->getDate((string)$item->date_added),
                        'title'         => (string)$item->title,
                        'description'   => (string)$item->description,
                        'url'           => (string)$item->url,
                        'added_date'    => $this->getDate((string)$item->date_added),
                        'related_extensions' => strtolower($item->related_extensions)
                    );

                    if($this->allowGetFeed($item_data)){
                        $noticeData[] = $item_data;
                    }
            }
            if($noticeData) 
            {
                $this->parse(array_reverse($noticeData));

                $this->setLastUpdate();
            }
        }
        return $this;
    }   

    public function allowGetFeed($item)
    {   
        if($item['related_extensions'] == null || $item['related_extensions'] == '0'){
            return true;
        }

        $modules = Mage::getConfig()->getNode('modules')->children();
        foreach ($modules as $moduleName => $moduleInfo) {
            if ($moduleName==='Mage_Adminhtml') {
                continue;
            }
            if ($moduleName==='Magestore_Magenotification') {
                continue;
            }           
            if(strpos('a'.$moduleName,'Magestore') == 0){
                continue;
            }
            $extension_code = str_replace('Magestore_','',$moduleName);
            $related_extensions  = explode(',',$item['related_extensions']);
            if(count($related_extensions)){
                foreach($related_extensions as $related_extension){
                    if(strtolower($related_extension) == strtolower($extension_code)){
                        return true;
                    }
                }
            }
        }
        return false;
    }

    public function getLastUpdate()
    {
        $timestring = Mage::getStoreConfig(self::XML_LAST_UPDATE_PATH);
        return strtotime($timestring);
    }

    public function setLastUpdate()
    {
        $config = Mage::getModel('core/config');
        $timestamp = Mage::getModel('core/date')->timestamp(time()); 

        $config ->saveConfig(self::XML_LAST_UPDATE_PATH,$timestamp);
        $config->cleanCache();
    }   

    public function getFrequency()
    {
        return Mage::getStoreConfig(self::XML_FREQUENCY_PATH) * 3600;
    }

    public function getMagestoreUrl()
    {
        $lastTimeNotice = strtotime($this->getLastNotice()->getAddedDate());
        return Mage::getStoreConfig(self::XML_MAGESTORE_URL_PATH) .'/magenotification/service/getfeed3/lastupdatetime/'. $lastTimeNotice;
    }

    public function getNotificationData()
    {   
        $curl = new Varien_Http_Adapter_Curl();
        $curl->setConfig(array(
            'timeout'   => 2
        ));
        $curl->write(Zend_Http_Client::GET, $this->getMagestoreUrl(), '1.0');
        $data = $curl->read();

        if ($data === false) {
            return false;
        }
        $data = preg_split('/^\r?$/m', $data, 2);
        $data = trim($data[1]);
        $curl->close();

        try {
            $xml = new SimpleXMLElement($data);
        }
        catch (Exception $e) {
            return false;
        }
        return $xml;
    }

    public function getNotificationXml()
    {
        try {
            $data = $this->getNotificationData();
            $xml  = new SimpleXMLElement($data);
        }
        catch (Exception $e) {
            $xml  = new SimpleXMLElement('<?xml version="1.0" encoding="utf-8" ?>');
        }

        return $xml;
    }

    public function getDate($rssDate)
    {
        return gmdate('Y-m-d H:i:s', strtotime($rssDate));
    }   

    public function parse($data)
    {
        if(count($data))
        {
            try{
                foreach($data as $item)
                {
                    if(!$this->is_existedUrl($item['url']) )
                    {
                        $this->setData($item)->save();
                        $this->setId(null);
                    }
                }
            } catch(Exception $e) {
                Mage::getSingleton('core/session')->addError($e->getMessage());
            }
        }
    }

    public function is_existedUrl($url)
    {
        $collection = $this->getCollection()
                        ->addFieldToFilter('url',(string)$url);         
        if($collection->getSize())
            return true;
        return false;
    }

    public function getLastNotice()
    {
        $item = $this->getCollection()
                        ->setOrder('added_date','DESC')
                        ->getFirstItem();
        return $item;
    }
}

找到 文档已移至此处。www.magestore.com上的Apache / 2.4.10(Debian)服务器端口80字符串无法解析为XML

找到 文档已移至此处。www.magestore.com上的Apache / 2.4.10(Debian)服务器端口80字符串无法解析为XML

当我单击此处时,它会显示一些xml和下面的消息,我想这意味着channel标记有问题:

This XML file does not appear to have any style information associated with it. The document tree is shown below.
<channel/>

您可以分享全部Magenotification.php吗?
路加·罗杰斯

@LukeRodgers,它现在在那里。感谢您的帮助。
Singleton

Answers:


5

对于可能遇到此问题的任何人,以下是“快速”修复程序:

更新此行:

$curl->write(Zend_Http_Client::GET, $this->getMagestoreUrl(), '1.0');

至:

$curl->write(Zend_Http_Client::GET, 'https://www.magestore.com/service/notification.xml', '1.0');

Magestore似乎已更改了其通知URL,因此上述更新应该可以解决。

我确实相信将扩展名Magestore_Magenotification更新到最新版本是推荐的修复程序。但是,如果您希望停止在system.log中充满此错误,则可以这样做。


3

显然,它试图解析的XML文件出了点​​问题。

您可以更改以下代码:

try {
    $xml = new SimpleXMLElement($data);
}
catch (Exception $e) {
    return false;
}

至:

try {
   $xml = new SimpleXMLElement($data);
}
catch (Exception $e) {
   echo $data . "\n";
   echo $e->getMessage();

   return false;
}

并将结果发布在这里?它应该打印出它试图解析的XML数据,并且它是错误消息,我确信它显示了一些有用的信息。


它已在上面添加。
Singleton

2

我看到有3个通知您。

  1. &lt;/body&gt;&lt;/html&gt;

  2. 此XML文件似乎没有与之关联的任何样式信息。文档树如下所示。

  3. 3。
$curl = new Varien_Http_Adapter_Curl();
        $curl->setConfig(array(
             'timeout'   => 2
        ));
        $curl->write(Zend_Http_Client::GET, $this->getMagestoreUrl(), '1.0');
        $data = $curl->read();

这意味着您的Url返回HTML字符串而不是XML字符串,您可以调试它并打印HTML响应吗,我认为您的控制器是错误的,而不是SimpleXMLElement

更新

让我解释更多

$curl = new Varien_Http_Adapter_Curl();
        $curl->setConfig(array(
            'timeout'   => 2
        ));
        $curl->write(Zend_Http_Client::GET, $this->getMagestoreUrl(), '1.0');
        $data = $curl->read();

$ this-> getMagestoreUrl() <==这是您的url请求(显示它)。

$ data = $ curl-> read(); 这是您对控制器(var_dump或print_r)此数据的响应文本。


将此添加到Magenotification.php文件中,看看它显示什么?@HoangHieu
辛格尔顿

不!。通知您。使用CURL收到请求后,您对$ this-> getMagestoreUrl() URL 的响应是什么问题,请检查HTML响应。
HoangHieu

我不确定如何使用您提供的代码。请解释更多。
Singleton

检查更新答案。
HoangHieu

我还是有些困惑,您给我的代码会引发错误。
Singleton
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.