登录 | 注册 | FAQ
Anonymous

'String could not be parsed as XML' error message

+ 发表回复

2 篇帖子 分页: 1 / 1


'String could not be parsed as XML' error message

comport9 » 周日 6月 08, 2014 4:32 am

My website has a news aggregator feature. It works most of the time except when the RSS feed isn't correct in some manner. I'd really like to know how to catch the error, and ignore it, so that the rest of the feeds can be loaded. Here is the error message I'm getting...



代码: 全选
Warning: SimpleXMLElement::__construct(): Entity: line 269: parser error : Opening and ending tag mismatch: description line 255 and script in /home3/sqiido/public_html/news.php on line 54

Warning: SimpleXMLElement::__construct(): // ]]></script> in /home3/sqiido/public_html/news.php on line 54

Warning: SimpleXMLElement::__construct(): ^ in /home3/sqiido/public_html/news.php on line 54

Warning: SimpleXMLElement::__construct(): Entity: line 271: parser error : Opening and ending tag mismatch: item line 228 and section in /home3/sqiido/public_html/news.php on line 54

Warning: SimpleXMLElement::__construct(): this article in full or to leave a comment, please click here</a></p></section> in /home3/sqiido/public_html/news.php on line 54

Warning: SimpleXMLElement::__construct(): ^ in /home3/sqiido/public_html/news.php on line 54

Warning: SimpleXMLElement::__construct(): Entity: line 271: parser error : Opening and ending tag mismatch: channel line 6 and article in /home3/sqiido/public_html/news.php on line 54

Warning: SimpleXMLElement::__construct(): cle in full or to leave a comment, please click here</a></p></section></article> in /home3/sqiido/public_html/news.php on line 54

Warning: SimpleXMLElement::__construct(): ^ in /home3/sqiido/public_html/news.php on line 54

Warning: SimpleXMLElement::__construct(): Entity: line 271: parser error : Sequence ']]>' not allowed in content in /home3/sqiido/public_html/news.php on line 54

Warning: SimpleXMLElement::__construct(): cle in full or to leave a comment, please click here</a></p></section></article> in /home3/sqiido/public_html/news.php on line 54

Warning: SimpleXMLElement::__construct(): ^ in /home3/sqiido/public_html/news.php on line 54

Warning: SimpleXMLElement::__construct(): Entity: line 271: parser error : internal error in /home3/sqiido/public_html/news.php on line 54

Warning: SimpleXMLElement::__construct(): cle in full or to leave a comment, please click here</a></p></section></article> in /home3/sqiido/public_html/news.php on line 54

Warning: SimpleXMLElement::__construct(): ^ in /home3/sqiido/public_html/news.php on line 54

Warning: SimpleXMLElement::__construct(): Entity: line 271: parser error : Extra content at the end of the document in /home3/sqiido/public_html/news.php on line 54

Warning: SimpleXMLElement::__construct(): cle in full or to leave a comment, please click here</a></p></section></article> in /home3/sqiido/public_html/news.php on line 54

Warning: SimpleXMLElement::__construct(): ^ in /home3/sqiido/public_html/news.php on line 54

Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /home3/sqiido/public_html/news.php:54 Stack trace: #0 /home3/sqiido/public_html/news.php(54): SimpleXMLElement->__construct('\n\n\n\n<rss versio...') #1 /home3/sqiido/public_html/news.php(178): getFeed('http://www.pcwo...', 'PC World') #2 {main} thrown in /home3/sqiido/public_html/news.php on line 54


Here is what I believe is the relevant code;

代码: 全选
function getFeed($feed_url, $rssTitle) {
   $lastLogin = $_SESSION["last_login"];
   $lastLogin = strtotime($lastLogin);
   
   $content = file_get_contents($feed_url);
   $ext = end(explode('.', $feed_url));

   $x = new SimpleXmlElement($content);
   
   $channelImage = ($x->channel->image->url);


I would like to simply use try/catch to "catch" the error and ignore it as I said. Right now it stops everything. To get anything else to show up I have to remove that feed. Any help would be greatly appreciated.
头像

comport9

  • 帖子: 28
  • 注册: 周日 11月 04, 2012 5:35 pm

Re: 'String could not be parsed as XML' error message

juliusijie » 周三 6月 11, 2014 3:53 pm

You can try this:
try {
/*the function commands here*/
}
catch (Exception $e) {
//write the error to a file
fopen("errors.txt", r+);
fwrite("errors.txt", $e->message);
fclose("errors.txt");
}
头像

juliusijie

  • 帖子: 19
  • 注册: 周六 2月 08, 2014 7:56 am
  • 地址: Lagos, Nigeria


+ 发表回复

分页: 1 / 1