DiscoBiscuit Posted February 22, 2009 Share Posted February 22, 2009 Hi, I'm trying to create a simple class to write RSS 2.0 feeds, but I'm having a few issues. 1: When I look at the source code of the feed, it begins on line 2, which I think may be related to the errors I'm receiving when trying to validate it. This feed does not validate. line 1, column 0: XML parsing error: <unknown>:2:0: XML or text declaration not at start of entity [help] In addition, interoperability with the widest range of feed readers could be improved by implementing the following recommendation. Feeds should not be served with the "text/html" media type 2: The titles of the items in my feed are not displaying, although they are actually shown in the source code. Here is an example with only one item in it: Source code: <rss version="2.0"><channel><title>Title goes here</title><description>Description goes here</description><link>Link goes here</link><copyright>Copyright goes here</copyright><item><title>Test post title</title><body>Test post body</body></item></channel></rss> What gets displayed: Description goes hereLink goes hereCopyright goes hereTest post body This is my class: class Rssfeed { private $feed; function __construct() { $this->feed = ""; } function addHeader($channel) { $this->feed = "<?xml version=\"1.0\"?>"; $this->feed .= "<rss version=\"2.0\">"; $this->feed .= "<channel>"; $this->feed .= "<title>".$channel["title"]."</title>"; $this->feed .= "<description>".$channel["description"]."</description>"; $this->feed .= "<link>".$channel["link"]."</link>"; $this->feed .= "<copyright>".$channel["copyright"]."</copyright>"; } function addNewsposts($newsposts) { foreach ($newsposts as $newspost) { $this->feed .= "<item>"; $this->feed .= "<title>".$newspost["title"]."</title>"; $this->feed .= "<body>".$newspost["body"]."</body>"; $this->feed .= "</item>"; } } function addFooter() { $this->feed .= "</channel>"; $this->feed .= "</rss>"; } function getFeed() { return $this->feed; } } And finally, how it is called: $feed = new Rssfeed(); $feed->addHeader($channel); $feed->addNewsposts($values); $feed->addFooter(); echo $feed->getFeed(); If anyone could help me work out what is going wrong it would be greatly appreciated, thanks:) Link to comment https://forums.phpfreaks.com/topic/146373-problems-with-rss/ Share on other sites More sharing options...
Mchl Posted February 22, 2009 Share Posted February 22, 2009 Maybe you have BOM outputted before actual XML? <body> is not valid element for <item> Also set up correct headers before outputting XML You might also try using xmlwriter which makes creating xml easy. Link to comment https://forums.phpfreaks.com/topic/146373-problems-with-rss/#findComment-768508 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.