XML Ayrıştırma Hataları


10

Ben bir sözdizimi hatası ya da bir şey var inanıyorum? Bunun xml veya sözdizimi ile ilgili olduğuna eminim. Dosyaya baktığımda her şey yolunda gibi görünüyor. Bu hata mage bildirimi modülü ile ilgili, değil mi? Sorun şu gibi kırık bir kod görmüyorum: <! 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

Bu Magenotification.php satır 126

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

Bana hiç yardım etmiyor.

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

Bulundu Belge buraya taşındı. Www.magestore.com adresindeki Apache / 2.4.10 (Debian) Sunucusu 80 numaralı bağlantı noktası XML olarak ayrıştırılamadı

Bulundu Belge buraya taşındı. Www.magestore.com adresindeki Apache / 2.4.10 (Debian) Sunucusu 80 numaralı bağlantı noktası XML olarak ayrıştırılamadı

Ben buraya tıkladığınızda bazı xml ve aşağıdaki mesajı getiriyor, sanırım kanal etiketi ile ilgili bir sorun var demektir:

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

Hepsini paylaşır Magenotification.phpmısın?
Luke Rodgers

@ LukeRodgers, şimdi orada. Yardım için teşekkürler.
Singleton

Yanıtlar:


5

Bu durumla karşılaşabilecek herkes için 'hızlı' bir düzeltme aşağıdadır:

Bu satırı güncelleyin:

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

Kime:

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

Magestore bildirim URL'sini değiştirdi, bu nedenle yukarıdaki güncelleme düzeltilmelidir.

Magestore_Magenotification uzantısı en son sürüme güncellenmesi önerilen düzeltme olduğuna inanıyorum. Ancak, system.log dosyasının bu hatayla dolu olmasını durdurmak istiyorsanız bu işlem yapılır.


3

Açıkçası, ayrıştırmaya çalıştığı XML dosyasıyla ilgili bir sorun var.

Aşağıdaki kodu değiştirebilir misiniz?

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

için:

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

   return false;
}

Ve sonuçları buraya gönderin? Ayrıştırmaya çalıştığı XML verilerini yazdırmalı ve hata mesajı, yararlı bir şey gösterdiğinden eminim.


yukarıda eklenmiştir.
Singleton

2

Bu 3'ün size bildirildiğini gördüm.

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

  2. Bu XML dosyasının kendisiyle ilişkilendirilmiş herhangi bir stil bilgisi yok. Belge ağacı aşağıda gösterilmiştir.

  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();

Bu senin URL dönüş anlamına HTML yerine dize XML dizesi bunu hata ayıklama ve yazdırabilirsiniz HTML , senin kontrolör yanlış değildi düşünüyorum tepkisini SimpleXMLElement

Güncellenmiş

Daha fazla açıklayayım

$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 () <== Bu sizin url isteğiniz (göster) ..

$ data = $ curl-> read (); bu, bu verilerin denetleyicisinin yanıt metninizdir (var_dump veya print_r).


Bunu Magenotification.php dosyasına ekleyin ve ne göründüğüne bakın? @HoangHieu
Singleton

Hayır!. size bildirir. sorun ne senin yanıttır $ this-> getMagestoreUrl () URL CURL kullanarak bir istek kazanılmış olmuştu zaman, kontrol, lütfen HTML yanıtı.
HoangHieu

Sağladığınız kodu nasıl kullanacağımdan emin değilim. Lütfen daha fazla açıklayın.
Singleton

Güncelleme cevabını kontrol edin.
Aralık'ta HoangHieu

Hala biraz kafam karıştı, bana verdiğiniz kod hata veriyor.
Singleton
Sitemizi kullandığınızda şunları okuyup anladığınızı kabul etmiş olursunuz: Çerez Politikası ve Gizlilik Politikası.
Licensed under cc by-sa 3.0 with attribution required.