Convert affiliate XML feed to RSS feed?

sgtrok

New member
Jun 10, 2008
58
0
0
www.ppvtactics.com
Does anyone know of an easy way to take an XML feed from an affiliate company and convert it into an RSS feed that could be used in other properties?

I was checking out datafeeds2rss, which is exactly what I was looking for, but it didn't work with the feed I needed to convert.

I glanced at the code, but couldn't figure out how to update the script to accept the XML feed I need to convert.
 


It's a case of "easy if you know how". All I can suggest is reading up on XML DOM parsers and how rss is formed. Or pay someone from odesk probably $10-20 ;)
 
Code:
<?php
error_reporting(E_ALL);

mysql_connect("localhost","root","root") or die (mysql_error());
mysql_select_db("oop") or die (mysql_error());

class RSS {

var $XMLdump;

var $pagetitle;
var $pagelink;
var $pegedescription;
var $pagelanguage;

var $sqlresult;

function setHead($setPagetitle, $setPagelink, $setPegedescription, $setPagelanguage){
	$this->pagetitle = $setPagetitle;
	$this->pagelink = $setPagelink;
	$this->pegedescription = $setPegedescription;
	$this->pagelanguage = $setPagelanguage;
}

function getDataFrom($setSQL){
	$this->sqlresult = mysql_query($setSQL);
}


function rssHead(){
	$this->XMLdump = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<rss version=\"2.0\" xmlns:atom=\"http://www.w3.org/2005/Atom/\">
	<channel>
		<title>".$this->pagetitle."</title>
		<link>".$this->pagelink."</link>
		<description>".$this->pegedescription."</description>
		<language>".$this->pagelanguage."</language>
		<lastBuildDate>".date("r", time())."</lastBuildDate>\n";
}

function rssItems(){
	while($bla = mysql_fetch_assoc($this->sqlresult)){
		$this->XMLdump .= "		<item>\n";
		$this->XMLdump .= "			<title>".$bla['title']."</title>\n";
		$this->XMLdump .= "			<link>http://bestnewssiteever.com/news/".$bla['id']."/</link>\n";
		$this->XMLdump .= "			<category>".$bla['category']."</category>\n";
		$this->XMLdump .= "			<pubDate>".date("r",$bla['pubDate'])."</pubDate>\n";
		preg_match_all("/^(?:[^.]*\.){3}/", $bla['content'], $trimedContent);
		$this->XMLdump .= "			<description>".$trimedContent[0][0]."..</description>\n";
		$this->XMLdump .= "		</item>\n";
	}
}

function rssFooter(){
	$this->XMLdump .= " 	</channel>
</rss>";
}

function writeXML(){
	$this->rssHead();
	$this->rssItems();
	$this->rssFooter();
	return $this->XMLdump;
}

function saveXML($file){
	$fp = fopen($file,"w+");
	flock($fp,2);
	fwrite($fp,$this->writeXML());
	flock($fp,3);
	fclose($fp);
}
}

$Bar = new RSS();
$Bar->getDataFrom("SELECT * FROM news ORDER BY pubDate DESC");
$Bar->setHead("TITLE","http://domain.de","DESCRIPTION","en-EN");
$Bar->saveXML("blub.xml");

?>

taken from OOP RSS/XML class for PHP - PHP - Snipplr Social Snippet Repository

next time use google diipshit
 
Code:
<?php
error_reporting(E_ALL);

mysql_connect("localhost","root","root") or die (mysql_error());
mysql_select_db("oop") or die (mysql_error());

class RSS {

var $XMLdump;

var $pagetitle;
var $pagelink;
var $pegedescription;
var $pagelanguage;

var $sqlresult;

function setHead($setPagetitle, $setPagelink, $setPegedescription, $setPagelanguage){
    $this->pagetitle = $setPagetitle;
    $this->pagelink = $setPagelink;
    $this->pegedescription = $setPegedescription;
    $this->pagelanguage = $setPagelanguage;
}

function getDataFrom($setSQL){
    $this->sqlresult = mysql_query($setSQL);
}


function rssHead(){
    $this->XMLdump = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<rss version=\"2.0\" xmlns:atom=\"http://www.w3.org/2005/Atom/\">
    <channel>
        <title>".$this->pagetitle."</title>
        <link>".$this->pagelink."</link>
        <description>".$this->pegedescription."</description>
        <language>".$this->pagelanguage."</language>
        <lastBuildDate>".date("r", time())."</lastBuildDate>\n";
}

function rssItems(){
    while($bla = mysql_fetch_assoc($this->sqlresult)){
        $this->XMLdump .= "        <item>\n";
        $this->XMLdump .= "            <title>".$bla['title']."</title>\n";
        $this->XMLdump .= "            <link>http://bestnewssiteever.com/news/".$bla['id']."/</link>\n";
        $this->XMLdump .= "            <category>".$bla['category']."</category>\n";
        $this->XMLdump .= "            <pubDate>".date("r",$bla['pubDate'])."</pubDate>\n";
        preg_match_all("/^(?:[^.]*\.){3}/", $bla['content'], $trimedContent);
        $this->XMLdump .= "            <description>".$trimedContent[0][0]."..</description>\n";
        $this->XMLdump .= "        </item>\n";
    }
}

function rssFooter(){
    $this->XMLdump .= "     </channel>
</rss>";
}

function writeXML(){
    $this->rssHead();
    $this->rssItems();
    $this->rssFooter();
    return $this->XMLdump;
}

function saveXML($file){
    $fp = fopen($file,"w+");
    flock($fp,2);
    fwrite($fp,$this->writeXML());
    flock($fp,3);
    fclose($fp);
}
}

$Bar = new RSS();
$Bar->getDataFrom("SELECT * FROM news ORDER BY pubDate DESC");
$Bar->setHead("TITLE","http://domain.de","DESCRIPTION","en-EN");
$Bar->saveXML("blub.xml");

?>
taken from OOP RSS/XML class for PHP - PHP - Snipplr Social Snippet Repository

next time use google diipshit

Outputs an RSS feed from mysql, not from an XML feed. Maybe your own google-foo is weak? Reminds me how glad I am to not use PHP anymore :)
 
mm... I thought RSS were just XML files (on my site, they are, at least). A function to search/replace wouldn't help you?

RSS is XML yes, but the structures of the 2 files will still probably be significantly different, making find and replace not that useful.