tryingtolearn Posted March 6, 2009 Share Posted March 6, 2009 I am parsing an rss feed and its working well but there is line that looks different and Im trying to figure out how I can get the info from it. The feed would look like this <item> <title><![CDATA[My Page Title]]></title> <link><![CDATA[http://sitename.com]]></link> <description><![CDATA[<table><tr><td>Description HTML Here</td></tr></table>]]></description> <pubDate>Fri, 06 Mar 2009 15:00:28 PST</pubDate> <rx:Category xmlns:rx="urn:site:apis:Components"><![CDATA[My Category Name]]></rx:Category> </item> Notice the line <rx:Category xmlns:rx="urn:site:apis:Components"><![CDATA[My Category Name]]></rx:Category> I need to display the My Category Name part The php code I am using is $doc = new DOMDocument(); $doc->load('xmlsource.xml'); $arrFeeds = array(); foreach ($doc->getElementsByTagName('item') as $node) { $itemRSS = array ( 'title' => $node->getElementsByTagName('title')->item(0)->nodeValue, 'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue, 'link' => $node->getElementsByTagName('link')->item(0)->nodeValue, 'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue ); array_push($arrFeeds, $itemRSS); } foreach ($arrFeeds AS $v){ foreach($v as $k){ echo "$k<br />"; } } It gets the title description link and pub date but I dont know what I can add to get the category as well Thanks for any help. Quote Link to comment https://forums.phpfreaks.com/topic/148254-parse-a-line-from-an-rss-feed/ Share on other sites More sharing options...
WolfRage Posted March 8, 2009 Share Posted March 8, 2009 Here you go. <?php $doc = new DOMDocument(); $doc->load('xmlsource.xml'); $arrFeeds = array(); foreach ($doc->getElementsByTagName('item') as $node) { $itemRSS = array ( 'title' => $node->getElementsByTagName('title')->item(0)->nodeValue, 'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue, 'link' => $node->getElementsByTagName('link')->item(0)->nodeValue, 'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue, 'rx'=>$node->getElementsByTagName('Category')->item(0)->nodeValue); //Notice this line. array_push($arrFeeds, $itemRSS); } foreach ($arrFeeds AS $v){ foreach($v as $k){ echo "$k<br />"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/148254-parse-a-line-from-an-rss-feed/#findComment-779498 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.