You are here:  » Parsing to an RSS file

Parsing to an RSS file

Submitted by rcasey on Fri, 2014-09-12 19:44 in

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?

Submitted by support on Fri, 2014-09-12 20:02


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">
  <title>Your Feed Title</title>
  <description>Your Feed Description</description>
    function myRecordHandler($record)
      print "<title><![CDATA[".$record["YOURTITLE"]."]]></title>";
      print "<link><![CDATA[".$record["YOURLINK"]."]]></link>";
      print "<description><![CDATA[".$record["YOURDESCRIPTION"]."]]></description>";
    $filename = "filename.xml";

Hope this helps!

Submitted by rcasey on Fri, 2014-09-19 17:13

Thanks! This worked perfectly.