xml - In PHP, create an ATOM Feed from an RDF based RSS Feed -
because of legacy system have produces old rdf based rss 1.0 feed, , inability of of rss readers handle http basic auth, i'd have php script reads feed , produces atom feed (as have nice reader here can handle http auth, looks nice, sadly cannot cope rss 1.0).
googling around time, pretty didn't find lot. code tried right now, xslt doesn't work, , don't know xslt), , got here. getting behind http basic auth worked, i'll leave in there:
$https_user = "thisismyhttpbasicusername"; $https_password = "thisismyhttpbasicpassword"; $https_server = "sometld.tld/dokuwiki/feed.php"; $opts = array('http' => array( 'method' => 'get', 'header' => "content-type: text/xml\r\n". "authorization: basic ".base64_encode("$https_user:$https_password")."\r\n", 'content' => $body, 'timeout' => 60 ) ); $context = stream_context_create($opts); $url = 'http://'.$https_server; $xml = file_get_contents($url, false, $context, -1, 40000); $xsl = file_get_contents("http://sometld.tld/minitools/rdf2atom.xslt"); $xsldoc = new domdocument(); $xsldoc->loadxml($xsl); $xmldoc = new domdocument(); $xmldoc->loadxml($xml); $proc = new xsltprocessor(); $proc->importstylesheet($xsldoc); echo $proc->transformtoxml($xmldoc); this xslt file:
<?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:template match="/"> <items> <xsl:copy-of select="//item"> <xsl:apply-templates/> </xsl:copy-of> </items> </xsl:template> </xsl:stylesheet> the output should elements, can wrap them element , have read rss reader doesn't handle rss 1.0 anymore.
the rss produced system looks this:
<rdf:rdf xmlns="http://purl.org/rss/1.0/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/"> <channel> ... </channel> <item rdf:about="http://sometld.tld/dokuwiki/doku.php?id=interessante_und_hilfreiche_links&rev=1368016122&do=diff"> <dc:format>text/html</dc:format> <dc:date>2013-05-08t14:28:42+02:00</dc:date> <dc:creator>akku</dc:creator> <title>interessante_und_hilfreiche_links</title> <link>http://sometld.tld/dokuwiki/doku.php?id=interessante_und_hilfreiche_links&rev=1368016122&do=diff</link> <description> * .net framework setup verification tool <- .net framework setup verification tool designed automatically perform set of steps verify installation state of 1 or more versions of .net framework on computer. verify presence of files, directories, registry keys , values .net framework. verify simple applications use .net framework can run correctly.</description> </item> <item>... more items ... </item> </rdf:rdf> do know php based script can transform rss 1.0 atom formatted feed? or can correctify xslt use? reference, actual output right looks this:
<?xml version="1.0"?> <items/>
this namespace issue. try add:
xmlns="http://purl.org/rss/1.0/" as namespace xslt stylesheet.
for example following xslt:
<?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform" xmlns:rss="http://purl.org/rss/1.0/"> <xsl:template match="/"> <items> <xsl:copy-of select="//rss:item" /> </items> </xsl:template> </xsl:stylesheet> will generate following output:
<?xml version="1.0"?> <items xmlns:rss="http://purl.org/rss/1.0/"> <item xmlns="http://purl.org/rss/1.0/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" rdf:about="http://sometld.tld/dokuwiki/doku.php?id=interessante_und_hilfreiche_links&rev=1368016122&do=diff"> <dc:format>text/html</dc:format> <dc:date>2013-05-08t14:28:42+02:00</dc:date> <dc:creator>akku</dc:creator> <title>interessante_und_hilfreiche_links</title> <link>http://sometld.tld/dokuwiki/doku.php?id=interessante_und_hilfreiche_links&rev=1368016122&do=diff</link> <description> * .net framework setup verification tool <- .net framework setup verification tool designed automatically perform set of steps verify installation state of 1 or more versions of .net framework on computer. verify presence of files, directories, registry keys , values .net framework. verify simple applications use .net framework can run correctly. </description> </item> <item xmlns="http://purl.org/rss/1.0/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/">... more items ... </item> </items>
Comments
Post a Comment