XML RSS Feed Parse PHP
Posted
by JD
on Stack Overflow
See other posts from Stack Overflow
or by JD
Published on 2010-04-21T09:57:54Z
Indexed on
2010/04/21
12:03 UTC
Read the original article
Hit count: 338
With an XML feed like so:
<w:current temperature="22.2" dewPoint="12.9" humidity="56" windSpeed="5.6" windGusts="9.3" windDirection="ESE" pressure="1017.8" rain="0.0" />
and
<w:forecast day="Thursday" description="Mostly Sunny. Warm." min="17" max="29" icon="2" iconUri="http://www.weather.com.au/images/icons/2.gif" iconAlt="Mostly Sunny" />
How do I parse it in PHP using the dom?
$doc = new DOMDocument();
$doc->load('http://rss.weather.com.au/sa/adelaide');
$arrFeeds = array();
foreach ($doc->getElementsByTagName('item') as $node) {
$itemRSS = array (
'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
'description' => $node->getElementsByTagName('w')->item(0)->nodeValue,
);
array_push($arrFeeds, $itemRSS);
}
Returns error :Notice: Trying to get property of non-object in /var/www/index.php on line 123
© Stack Overflow or respective owner