Hello, I'd like to parse an XML file to create a separate RSS feed. I realize that XSLT is likely an option to transform my XML, but I'm going to need to use array substitutions and if statements in creating this and figured PHP is the easiest route there.
Anyway, I wanted to see if MagicParser would be capable of aiding me in this process?
Hi,
Sure - here's an "outline" example that would create a valid RSS 2.0 document containing title, link and description elements for each item based on corresponding YOURTITLE, YOURLINK and YOURDESCRIPTION elements from the $record array as passed to your myRecordHandler function when parsing "filename.xml" with format string "xml|FORMAT/STRING/":
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title>Your Feed Title</title>
<link>http://www.example.com/</link>
<description>Your Feed Description</description>
<?php
require("MagicParser.php");
function myRecordHandler($record)
{
print "<title><![CDATA[".$record["YOURTITLE"]."]]></title>";
print "<link><![CDATA[".$record["YOURLINK"]."]]></link>";
print "<description><![CDATA[".$record["YOURDESCRIPTION"]."]]></description>";
}
$filename = "filename.xml";
MagicParser_parse($filename,"myRecordHandler","xml|FORMAT/STRING/");
?>
</rss>
Hope this helps!
Cheers,
David
--
MagicParser.com