Opening and ending label mismatch and premature end of data in rss tag

I am trying to parse the RSS feed at this link http://www.gazetaexpress.com/rss.php?cid=1,13&part=rss but when I try to display the results, it causes the following error:

Warning: DOMDocument :: load () [domdocument.load]: discrepancy between opening and ending tags: strong line 208 and description at http://www.gazetaexpress.com/rss.php?cid=1,13&part=rss , line: 209 in C: \ wamp \ www \ gazetaExpress \ scripts \ reader.php on line 17

and

Warning: DOMDocument :: load () [domdocument.load]: premature end of data in rss tag line 2 at http://www.gazetaexpress.com/rss.php?cid=1,13&part=rss line: 226 in C : \ wamp \ www \ gazetaExpress \ scripts \ reader.php on line 17

the script that I use for parsing,

$xmlDoc->load($xml); $x=$xmlDoc->getElementsByTagName('item'); for ($i=0; $i<6; $i++) { $item_title=$x->item($i)->getElementsByTagName('title')->item(0)->childNodes->item(0)->nodeValue; $item_link=$x->item($i)->getElementsByTagName('link')->item(0)->childNodes->item(0)->nodeValue; $item_desc=$x->item($i)->getElementsByTagName('description')->item(0)->childNodes->item(0)->nodeValue; // and echo statements } 

When I try any other rss channel from this site (for example, sports: http://www.gazetaexpress.com/rss.php?cid=1,24&part=rss ), it works fine. This is exactly the above rss feed that will not work. Is there any way around this? any help would be greatly appreciated.

+6
source share
2 answers

This is due to the use of <br> and other closing tags. Dom is trying to find the end <br/> where <br starts, and /> end. Modern browsers won't have a problem with <tag> , but the php dom function still wants you to keep the XML standard, so you need to find al <singletags> and replace them with <singletags /> , which just works.

+6
source

When the fragment you want to parse does not meet the XML specifications (for example, tags that close closures without // or closed tags), and if it does not contain duplicate identifiers, you can try with loadHTML , it is more permissive.

 $xmlDoc->loadHTML($xml); 
+4
source

Source: https://habr.com/ru/post/910826/


All Articles