Reputation: 2203
I have used PHP with simplexml to parse RSS using standard elements before like <title> <pubDate>
etc. But how would I parse something custom to the feed like <xCal:location>
or <xCal:dtstart>
that uses an xCal data element?
Something like $item->xCal:dtstart
will error out. How would I collect this data element?
A sample of a feed like this: http://www.trumba.com/calendars/vd.rss?mixin=236393%2c236288
Upvotes: 3
Views: 375
Reputation: 97718
The "something custom" is an XML namespace. Search for existing answers regarding SimpleXML and namespaces.
Basically, what you need is the ->children()
method: $item->children('xCal', true)->dtStart
Upvotes: 0
Reputation: 1457
Try like this:
$feedUrl = 'http://www.trumba.com/calendars/vd.rss?mixin=236393%2c236288';
$rawFeed = file_get_contents($feedUrl);
$xml = new SimpleXmlElement($rawFeed);
$ns = $xml->getNamespaces(true);
//print_r($ns);
$xCal = $xml->channel->children($ns['xCal']);
echo ($xCal->version)."<br />";
foreach($xml->channel->item as $item)
{
//print_r($item);
$itemxTrumba=$item->children($ns['x-trumba']);
echo $itemxTrumba->masterid."<br />";
}
//print_r($xCal);
Upvotes: 3