PHP simplexml_load with CDATA
Hi everybody!
I'm trying to scrape some data from an XML file that contains content inside CDATA tags and I'm having trouble with it.
feed.XML file:
<?xml version="1.0" encoding="UTF-8"?>
<channel>
<item>
<pubDate><![CDATA[Thu, 17 Sep 2015 16:02:53 -0700]]></pubDate>
<title><![CDATA[Hello world!]]></title>
<url><![CDATA[http://example.com/?id=hello_world]]></url>
</item>
</channel>
PHP:
<?php
if (file_exists('feed.xml')) {
$xml = simplexml_load_file('feed.xml');
echo $xml->channel->item->pubDate;
} else {
exit('Failed to open xml.');
}
?>
Error:
Trying to get property of non-object in feed.xml
If I print_r $xml
I get an array of nodes but no content from [CDATA] tags.
What am I missing?
Nancy O.

