suin/php-rss-writer

No tags with a colon possible

Closed this issue · 2 comments

Hi,

I wanted to add the <itunes:image> tag for my podcast feed but php-rss-writer cut it in half and only made <image> out of it.
I'm unsure where this happens.
You can find my code here: https://github.com/repat/php-rss-writer/blob/master/Source/Suin/RSSWriter/Channel.php

An example where I used this code: http://repat.de/ohrenbaer-feed/

cheers

suin commented

Hi repat,

you would have to specify XML namespace when you add <itunes:image> node.

Try following snippet:

<?php

$xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8" ?><rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">', LIBXML_NOERROR|LIBXML_ERR_NONE|LIBXML_ERR_FATAL);

$itunesImage = $xml->addChild('itunes:image', null, 'http://www.itunes.com/dtds/podcast-1.0.dtd');
$itunesImage->addAttribute('url', 'http://example.com/example.png');

$result = $xml->asXML();

echo $result;

The result of the above code:

<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"><itunes:image url="http://example.com/example.png"/></rss>

I changed Channel.php a bit and if I then add the image to the channel I get

<itunes:image xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" href="http://www.example.com/logo.png"/>

But it works anyway in the podcatcher, thanks!