1

I've searched a lot over the past few days but i'm now resigning to asking for help.

I'm parsing a number of news websites using PHP's simplexml_load_file(), my code is below....

foreach ($sourceID as $s) {

$xml = simplexml_load_file($s['rss']);

$dateTimeArray = [];

if ($xml != false) {
foreach($xml->channel->item as $item)
{       
    foreach($item->pubDate as $date) {
        $dateTimeArray[] = (string) $date;
    }

    $s['dateTimeList'] = $dateTimeArray;        
}
array_push($source, $s);
} else {

echo 'error '.$s['id'];
}
}

There are some sites that have "This XML file does not appear to have any style information associated with it. The document tree is shown below." displayed at the top, this is something to do with not being correctly read as an XML document?

Ultimately my php code will not parse any data from the websites that display this message, any help that can be easily added to my present code would be greatly appreciated.

One of the xml feeds in question is this one https://cointelegraph.com/rss

Thanks!

JakeB
  • 2,043
  • 3
  • 12
  • 19
  • In principal there's nothing obviously wrong about your code. The "This XML file does not appear to have any style..." message is unrelated and probably just coincidental that the feeds showing that message correlate with your code not being able to parse it. Provide a full example using a real xml feed instead to get help with this. – Evert Jun 02 '17 at 19:02
  • Its just a notice. XML files can be styled just like HTML using css. However if none is present it can give you that notice and just print out the source, being the XML data - its nothing to worry about. For more info see https://stackoverflow.com/questions/14804452/opening-facelets-page-errors-with-this-xml-file-does-not-appear-to-have-any-sty If you want to avoid those check if the xml-stylesheet tags exist or not — how ever when it comes to pure data loading Id consider one without style sheets valid over one with as data doesn't need fancy styling before its valid. – Jenne Jun 02 '17 at 19:11
  • Added an rss feed that isnt working as an example: https://cointelegraph.com/rss – JakeB Jun 02 '17 at 20:18

1 Answers1

0

Fixed this by setting a specific browser:

ini_set("user_agent","Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Mobile Safari/537.36");
JakeB
  • 2,043
  • 3
  • 12
  • 19