TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   Parse XML categories and create RSS feed out of it... (http://www.talkphp.com/general/3902-parse-xml-categories-create-rss-feed-out.html)

buildakicker 01-21-2009 04:31 PM

Parse XML categories and create RSS feed out of it...
 
Hello all,

So I am thinking of having an XML file that contains a few different categories. Is there a way to use php to create the RSS feed for each different category?

For example:
Code:

<items>
<item>
<title></title>
<description></description>
<link></link>
<pubDate></pubDate>
<category>Fire</category>
</item>

<item>
<title></title>
<description></description>
<link></link>
<pubDate></pubDate>
<category>Recreation</category>
</item>
</items>

One RSS feed for Fire, One for Recreation, parsed from the same XML file.

Then link to it like: rss.xml for the feed readers.

Thanks!

xenon 01-21-2009 05:38 PM

file_put_contents?

Salathe 01-21-2009 06:07 PM

Here's just one idea. The process is simply: find items which don't belong to our requested category and delete them.

PHP Code:

/**
 * Filtering an RSS feed by category.
 */

// Load the XML feed
$dom = new DOMDocument();
$dom->load(\'http://www.talkphp.com/external.php?type=RSS2\');


// Query for the items we want to throw away
$xpath = new DOMXPath($dom);
$nodes $xpath->query('//item[not(category = "General")]');

// Remove those unwanted items
foreach ($nodes as $node)
{
    
$node->parentNode->removeChild($node);
}

// Output the filtered document
header('Content-Type: application/xml; charset='.$dom->encoding);
echo 
$dom->saveXML(); 


buildakicker 01-21-2009 06:29 PM

Quote:

Originally Posted by Salathe (Post 21368)
Here's just one idea. The process is simply: find items which don't belong to our requested category and delete them.

PHP Code:

/**
 * Filtering an RSS feed by category.
 */

// Load the XML feed
$dom = new DOMDocument();
$dom->load(\'http://www.talkphp.com/external.php?type=RSS2\');


// Query for the items we want to throw away
$xpath = new DOMXPath($dom);
$nodes $xpath->query('//item[not(category = "General")]');

// Remove those unwanted items
foreach ($nodes as $node)
{
    
$node->parentNode->removeChild($node);
}

// Output the filtered document
header('Content-Type: application/xml; charset='.$dom->encoding);
echo 
$dom->saveXML(); 


Thanks for the idea. I see what you are doing there... I only have php4 though... I will try and do something with domxml if I can figure it out there.


All times are GMT. The time now is 04:40 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0