RSS XML documents generated by the 'Feed' display begin with a blank line, before the XML declaration. This goes against to the official XML definition and prevents the feed from being detected by, at least, Firefox (and possibly other browsers).

When tested with a 'Feed' display attached to 'Master' display, no feed icon appears in the address bar. This setup would normally show the icon in the browser's address bar rather than next to the view (like when attached to any "non-master" displays). The html tag is properly injected in the template but the error in the XML document prevents proper handling by the browser.

When tested with the 'Feed' display attached to a 'Block' display, the feed icon is properly displayed but clicking on it fails to open the feed (the browser treats the link like a regular file and tries to download it).

Comments

mesr01’s picture

The error returned by Firefox 6:

XML Parsing Error: XML or text declaration not at start of entity
Location: file:///home/raphael/Desktop/rss.xml
Line Number 2, Column 1:<?xml version="1.0" encoding="utf-8" ?><rss version="2.0" xml:base="http://mysite.com/path/to/view" xmlns:dc="http://purl.org/dc/elements/1.1/">
^
merlinofchaos’s picture

Status: Active » Closed (won't fix)

This almost always means that some file you have has a CR before the <?php> tag, and that's what is generating the extra linefeed. You can double check the template being used by the feed, of course, to make sure there isn't an extra CR there, but typically Views XML is formed correctly in this case and every time this has been reported, it has always been a local site issue.

mesr01’s picture

I don't know where to look then, since my theme uses all default templates except for page.tpl.php, and no preprocess function is defined neither. So I cannot see where the views output is being altered. Would you have any clues?

mesr01’s picture

Version: 7.x-3.0-rc1 » 7.x-3.0-rc3
Priority: Major » Normal
Status: Closed (won't fix) » Active

There is indeed a problem with the default feed rendering. A very basic site here, no template override and still, this blank line is fed before the XML declaration. It seems that the problem has its root deeper than templating because there is no residual CR in the template file (views/theme/views-view-rss.tpl.php). This error is ignored in most browsers, but Firefox, since the document is not well formed, will download it instead of processing it.

merlinofchaos’s picture

Status: Active » Closed (won't fix)

I recommend you use grep to look for files that have a CR before their <?php tag or something similar. If that CR is not in the views template, it is 99.9% likely to be in some other file that gets loaded in your site.

Since no one else is reporting this, I am highly dubious that it is a problem in VIews, but it is somewhere in your site. If not your theme (the usual culprit) it could be a misbehaving module or something. all files that get loaded have the potential to do this.

Unless you can positively identify Views as actually doing this somehow, I am not going to spend time chasing a ghost when I have a high confidence Views isn't doing it.

nykooa’s picture

I have the same problem. I have a blank line at the begining and firefox is trying to download the rss feed instead of display it.

I am a newbie in XML declaration, but in views-view-rss.tpl.php I changed this

<?php print "<?xml"; ?> version="1.0" encoding="utf-8" <?php print "?>"; ?>
<rss version="2.0" xml:base="<?php print $link; ?>"<?php print $namespaces; ?>>

for this

<?php print "<?xmlns"; ?> version="1.0" encoding="utf-8" <?php print "?>"; ?>
<rss version="2.0" xml:base="<?php print $link; ?>" xmlns:atom="http://www.w3.org/2005/Atom" <?php print $namespaces; ?>>

I still have a blank line, but my feed is displayed correctly and is valid for W3C.

mesr01’s picture

I haven't discovered yet which module is causing this interference but, in the meantime, it's a clever fix!

abaier’s picture

Thanks! #6 fixed the problem for me too.

mariafromatoz’s picture

Ta! #6 worked for me as well.

xmacinfo’s picture

Nice fix in #6 . Way quicker than looking for a space in a haystack.

But still, the best solution would still be doing a grep to find the culprit.

ParkerDMartin’s picture

Fix #6 works in Firefox and IE, but for some reason, it doesn't fix the error in Chrome.
Any advice or any further information someone can provide?

luigisa’s picture

Fix #6 works in Firefox and IE

SharonD214@aol.com’s picture

Fix #6 work for me in Chrome as well.

Thanks!

Sk8erPeter’s picture

As merlinofchaos said, this really has nothing to do with Views. The "fix" in #6 is NOT actually a fix...

In my case, I had two whitespaces in front of the <?xml tag, so the RSS feed started like this: " <?xml".
I never thought I will find the source of the problem with such an ugly solution, but this is quick and works - it's really dirty, so use it only on a local development copy, do NOT test it on a production site:
https://drupal.org/node/175137#comment-1526410
in includes/module.inc file, in the module_load_all() function, after the drupal_load('module', $module);, soyarma suggests you to put in the following line temporarily: print $module.'|';
This way you'll get a list of your modules in the beginning of the output separated by the pipe (|) character. When there are unnecessary whitespaces before the module's name and the pipe character, then you just found the buggy module.

For example, in my case, Views Slideshow was the source of the problem:
views_bulk_operations|views_content| views_slideshow|views_slideshow_cycle
(this is just the end of the huge list)

As you can see, there are two spaces before views_slideshow. This is where I should start searching for the source of the problem. I found it in views_slideshow/theme/views_slideshow.theme.inc: the code starts with two whitespaces, and the PHP block is just after that: " <?php"
You can also see it here:
http://drupalcode.org/project/views_slideshow.git/blob/d9fd60c20add43a7b...

And YESSS, after deleting the two spaces, http://validator.w3.org/ congratulated me that my RSS feed is valid. Thank you, soyarma!

Don't forget to revert the changes in module.inc (don't ever hurt the core's code! :) ), and delete the print $module.'|'; line.

I'll report an issue to the Views Slideshow's queue, and I hope that this helped someone.

====
EDIT:
I reported the bug to the issue queue, and also created a patch, see #2078689: Unnecessary two whitespaces before the PHP code block in views_slideshow.theme.inc, which can cause RSS feeds to get invalid.

manimaran.purusothaman’s picture

Post #14 is good solution for fixing RSS feed issue.

In addition to that try to remove the "?>" tag at the end of ".module" file and template.php. Because it will add some white spaces.

I got fixed the RSS feed issue by removing "?>" tag at the end of ".module" file

W.M.’s picture

Issue summary: View changes

Thanks @Sk8erPeter

Solution under #14 can save a lot of time and effort in order to find the where the extra lines are located.

sarathkm’s picture

Here is another way of using grep to find the culprit. Mostly it is module file so...
grep -R -H '^ <?php' modules/**/*.module
This will check all module files withing your module folder ( i am a step back in my sites/all folder in my linux terminal to find culprit.)
If you find two spaces leave two space between ^ and <?php, if one space leave one.
you will get the path of file which is culprit.

If you just get the filename you can find its path via
locate -br 'culprit.module'

After correcting clear cache. :)

Regards To All

blur702’s picture

#15 was the fix for me with the ?> at the end of my template.php file.

It removed the space at the top at least.