Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/148254-parse-a-line-from-an-rss-feed/
Share on other sites

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 />";
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.