26

I have this script to generate an XML file for an RSS feed. Works great in every browser except Chrome. Chrome just renders the XML as text. Something to do with header("Content-Type: application/rss+xml; charset=ISO-8859-1"); possibly?

This is the code I'm using:

<?php

$linkUp = "http://localhost/sites/myBlog/";

header("Content-Type: application/rss+xml; charset=ISO-8859-1");

$rssfeed  = '<?xml version="1.0" encoding="ISO-8859-1"?>';
$rssfeed .= '<rss version="2.0">';
$rssfeed .= '<channel>';
$rssfeed .= '<title>Mytitle</title>';
$rssfeed .= '<link>' . $linkUp . '</link>';
$rssfeed .= '<description>Mydescription</description>';
$rssfeed .= '<language>en-us</language>';
$rssfeed .= '<copyright>&copy; ' . strftime('%Y') .  ' . " " . ' . $linkUp . '</copyright>';


$query = "SELECT * FROM rss";
$result = $db->query($query);

while($row = $db->fetch_array($result)) {

    $rssfeed .= '<item>';
    $rssfeed .= '<title>' . $row['rss_title'] . '</title>';
    $rssfeed .= '<description>' . $row['rss_description'] . '</description>';
    $rssfeed .= '<link>' . $row['rss_link'] . '</link>';
    $rssfeed .= '<pubDate>' . date("D, d M Y H:i:s O", strtotime($date)) . '</pubDate>';
    $rssfeed .= '</item>';
}

$rssfeed .= '</channel>';
$rssfeed .= '</rss>';

echo $rssfeed;

?>
Scott
  • 823
  • 4
  • 11
  • 21
  • 1
    You should be escaping data when you concatenate it into XML, otherwise you may be vulnerable to the same risks as with HTML injection. `htmlspecialchars` works for XML as well as HTML. Note for `` if your description is text you need to HTML-escape it *twice* as otherwise it is handled as HTML. Also, you shouldn't be using entity references like `©` in an XML file as they are not predefined entities like in HTML (unless you include an RSS DOCTYPE that does define them). Use character references such as `©` or simply a direct `©` ISO-8859-1 byte in preference. – bobince Nov 01 '09 at 13:28
  • As a rule of thumb, if you are generating XML, then use an XML library, not a template. – Quentin Feb 12 '10 at 12:51

6 Answers6

26

This is a known bug in chrome that has yet to be fixed, chrome does not display xml rss feeds with any formatting whatsoever.

Update: There is now an RSS subscription / reader extension for Chrome.

Wedge
  • 19,513
  • 7
  • 48
  • 71
  • 2
    Can't believe this has been an issue for over a year. – Scott Nov 01 '09 at 08:07
  • 2
    Try adding "view-source:" in front of the "http://..." URL of your RSS feed in Chrome - at least you'll see some syntax coloring of xml tags – Arne Roomann-Kurrik Mar 04 '10 at 19:12
  • 1
    You post this in 2009 and now it's 2015 and just came here because of this behaviour. I don't think they have plans to fix this because it's 'old' tech. Weird. – Codebeat Mar 27 '15 at 04:56
5

I had this same problem and I used "application/xml" and it fixed it right up. Chrome doesn't like "application/rss+xml".

Andrew Christensen
  • 862
  • 2
  • 14
  • 22
2

Bottom line, RSS support isnt used by "majority" of users, and as such they are only implementing it as an extension, for now. The extension is available here: RSS SubscriptionExtension

There's a detailed discussion of this on the closing comment for the bug - you can read the developer notes here: Comment 149

danp
  • 14,876
  • 6
  • 42
  • 48
1

Try changing the header to text/xml and see if it helps:

header("Content-Type: text/xml; charset=ISO-8859-1");
Traveling Tech Guy
  • 27,194
  • 23
  • 111
  • 159
1

try the chrome extension "XML Tree"

EddieO
  • 11
  • 1
0

Short answer: add "view-source:{feedurl}"

Note that when the url ends with .xml and is recognized as a feed by chrome, Chrome annoyingly opens a Save File dialog. But many feed urls don't end with an extension (i.e. .xml), such as:

http://feeds.feedburner.com/ScottHanselman

At root, that url is still a regular, xml feed, but for us coders who just want to see the real xml, Chrome and the others in this case show you a human readable display of the feed (very annoying!).

So the answer to both of these problems is contained in the comment above given by Arne Roomann-Kurrik. He should have put it as an answer, because it works!

view-source:http://feeds.feedburner.com/ScottHanselman You don't even need "http://".

Nicholas Petersen
  • 9,104
  • 7
  • 59
  • 69