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과 아래 메시지가 표시됩니다. 채널 태그에 문제가 있음을 의미합니다.

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

당신은 전체를 공유 할 수 있습니까 Magenotification.php?
Luke Rodgers

@LukeRodgers, 지금 거기에 있습니다. 도움을 주셔서 감사합니다.
싱글 톤

답변:


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 데이터를 인쇄해야하며 오류 메시지이므로 도움이되는 것으로 보입니다.


위에 추가되었습니다.
싱글 톤

2

나는 당신에게 3 알림을 보았다.

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

  2. 이 XML 파일과 관련된 스타일 정보가 없습니다. 문서 트리는 아래와 같습니다.

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

즉 , XML 문자열 대신 Url이 HTML 문자열을 반환한다는 것을 디버깅하고 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
당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.