I want to parse some XML rss feeds that I got from curl with XMLReader and SimpleXML for "faster" reason.
However it can't be parse to xml due to the result of curl is string:
$element = new SimpleXMLElement($xml->readOuterXML()); //String could not be parsed as XML
Here is my code:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, get_post_meta($post_id->ID, 'feed', true)); //https://wordpress.org/news/feed/
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_ENCODING , 'gzip, deflate');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$rss = curl_exec($ch);
curl_close($ch);
$xml->xml($rss);
while ($xml->read()){
if ($xml->nodeType == XMLReader::ELEMENT){
$element = new SimpleXMLElement($xml->readOuterXML()); //String could not be parsed as XML
foreach ($element as $channel){
foreach ($channel->item as $item){
//Loop Process
}
}
Am I missing something or wrong at some point?