Submitted by aslater on Fri, 2009-06-12 14:37 in Magic Parser
Hello is it possible to use magic parser to actually create an RSS feed? I have a number of XML data files and I want to take to the first few results from each file and and output them as an RSS feed. Is thsi possible to do with MP?
Magic Parser as just a parser doesn't have any functionality with regards to creating XML, which is actually relatively straight forward. All you need to do is declare the content type of the output of your script as text/xml, and then generate the RSS XML as your output instead of HTML.
Taking your example of combining the first few results of a number of feeds into a single XML feeds, have a look at the following code. I've assumed that the input feeds are also RSS - if not, simply use the appropriate keys into $record instead of TITLE, DESCRIPTION and LINK....
Hi,
Magic Parser as just a parser doesn't have any functionality with regards to creating XML, which is actually relatively straight forward. All you need to do is declare the content type of the output of your script as text/xml, and then generate the RSS XML as your output instead of HTML.
Taking your example of combining the first few results of a number of feeds into a single XML feeds, have a look at the following code. I've assumed that the input feeds are also RSS - if not, simply use the appropriate keys into $record instead of TITLE, DESCRIPTION and LINK....
<?php
require("MagicParser.php");
header("Content-Type: text/xml");
function myRecordHandler($record)
{
global $c;
print "<item>";
print "<title>".$record["TITLE"]."</title>";
print "<link>".$record["LINK"]."</link>";
print "<description><![CDATA[".$record["DESCRIPTION"]."]]></description>";
print "</item>";
$c++;
if ($c == 3) return TRUE;
}
print "<rss>";
print "<channel>";
$c = 0;
MagicParser_parse("feed1.xml","myRecordHandler","xml|RSS/CHANNEL/ITEM/");
$c = 0;
MagicParser_parse("feed2.xml","myRecordHandler","xml|RSS/CHANNEL/ITEM/");
$c = 0;
MagicParser_parse("feed3.xml","myRecordHandler","xml|RSS/CHANNEL/ITEM/");
print "</channel>";
print "</rss>";
?>
Hope this points you in the right direction!
Cheers,
David.