I'm at a bit of a loss on this one... my personal site is not generating a valid RSS feed:
http://feedvalidator.org/check.cgi?url=http%3A%2F%2Fwww.emmajane.net%2Fr...

However, a site hosted on the same system with multisite is fine:
http://feedvalidator.org/check.cgi?url=http%3A%2F%2Fwww.gbcn.ca

If I use garland (the same theme that I'm using for the functioning site), I still get a blank line at the top and bottom of the RSS feed. The front page is using using a custom view; however, even when I go to the standard blog display (http://emmajane.net/blog/1/feed) I still get the blank lines.

I'm not sure where to start with this problem. If it were theme-specific I'd know where to start, but I'm a bit stumped on this one. Any pointers would be much appreciated!

Comments

soyarma’s picture

usually this issue is from a blank line at the top or bottom of a module file. This is the reason why it's recommend not to put the closing ?> in your module files as a space can sometimes sneak in at the end.

This can be a HUGE pain to sort out, especially if you have a lot of custom modules. Here's how to find the culprit:

In your module.inc file (in the includes folder) add this after the drupal_load function in the module_load_all function

print $module.'|';

You'll get a huge mash of modules, but the one that starts on line 2 will be your culprit module

randomuser’s picture

My RSS feeds are the same but when I try your suggestion above the modules print out all on the one line.
Is there another way to help debug this?

I thought it was going to be tedious to go through all the modules making sure that they didn't close the PHP at the end but it actually turned out pretty easy by dragging all the .module files into Ultraedit and searching through 'all open tabs' for ?>.

After removing the 6 or so it found I also checked the the template.php which had serveral instances and what turned out to be the issue. So it you are having trouble with blank lines in your RSS feeds the first place I would check is template.php before doing a bulk search through the .module files.

tripper54’s picture

Hi,

I have the same problem.

I have tried the suggestion by soyarma above, but all my modules printed on one line.

I tried searching for ?> in .module & .inc files, to no avail.

I tried disabling all contrib modules, problem still persists.

I tried deleting all contrib modules from my site, no dice.

I tried changing to garland theme (also deleted all other theme folders), problem still persists.

I'm going crazy here - can anyone else suggest anything I should try to get this working?

------------------
Phil Dodd
twitter: @phildoddau

tripper54’s picture

Hi all,

I still don't know what caused it, but I managed to solve the problem by replacing every file on the site except .htaccess and the sites folder with a fresh download of drupal.

Something errant must have found its way into the core files at some stage. I will never know what.

------------------
Phil Dodd
twitter: @phildoddau

anup.tilak’s picture

I'm new bee to the Drupal, what could be the issue with template, particularly I should look? I'm using feedburner to get my feeds. Somehow I get blank feed when I post new post on site.

Can you please give me an idea where I should look, so that I can solve this problem.

soyarma’s picture

On possibility is ASCII FTP transfer. That is most likely what was the problem for the user above. The default setting for most FTP transfers is ASCII, which transfers everything as text. However sometimes, between some clients/servers this can cause issues.

You could try setting your FTP software to binary and uploading everything. Also, you could try disabling the theme you are using and enabling Garland.

If that doesn't work, you could try what I did in response 1, but that may be something you're not comfortable with--in which case you'll have to turn modules off one by one to find the culprit.

However, (to my knowledge) it is only 1 of 3 things

1. Module with bad ?> tag
2. Theme with bad ?> tag
3. ASCII File transfer mucked up files

crispynewt’s picture

hi,

thanks for this thread - it got me headed in the right direction :)

turns out that my issue was slightly different and was caused by the fact that I'm developing on Windows and hadn't configured Eclipse to ensure that file encoding and characters are Unix friendly...

see: http://drupal.org/node/75242#PDT

this was resulting in non-printable characters being output at the beginning of my pages and RSS feed.

hope that helps someone :)

bsufan17’s picture

Thank you for the tip on the template.php file. That is where I found the problem, and probably never would have found it, had you not mentioned it.

Vaene’s picture

Oldy but a goody, we had a blank line before our <?php in the theme's template.php file, took it out and rss worked!

robwalte’s picture

I know this an old thread, but thank you for the print $module.'|'; suggestion! It pointed me to the culprit module - one I forgot I'd even made, complete with five closing ?> tags...exactly equalling the number of blank lines ahead of my xml declaration in any rss file.

If anyone else is having problems with their xml feed being malformed, or having lines added to the top of their rss.xml file, try this first!

ealtman’s picture

Thank you thank you thank you for posting this blank line detection solution -- never would have thought of it ourselves.

guusbosman’s picture

Thank you Soyarma! Your advice helped me find the issue very quickly (in a home-written module).

jaypabs’s picture

@soyarma

thank you very much. after long hours of working with this problem I solve it by using your code print $module.'|';

laevensv@gmail.com’s picture

Thank you for this tips ! Very helpful :)

n8thanael1900’s picture

Perfect!  Thanks!

xjessie007’s picture

Hi, I just had a problem with having a blank line at the beginning of a page too (just before the DOCTYPE declaration). This caused the

Invalid xml declaration.
 Line: 2 Character: 3

error message when accessing the rss.xml page. This is often caused by having a blank line before the opening ?php tab in some of your *.module file. Here is a "how to" for finding the *.module that causes the blank line.

First, let me explain the logic behind the blank line. Drupal generates the page at some point. In case there is some piece of code that includes something outside PHP, it gets sent to the browser sooner than the page is generated by Drupal. And this is the blank line in our case. So, in order to find the code that sends something to the browser sooner than the whole page is put together by Drupal, you can switch off output buffering and let the site generate a warning for you. Go to your php.ini and uncomment the output_buffering parameter. This will turn off the buffer at the server and cause the server to send stuff to the browser as it generates it, the server will not wait until the whole page is put together to send it. Restart the server. This will cause a warning at your site similar to the following:

warning: Cannot modify header information - headers already sent by (output started at C:\User\web\WWW_ROOT_80\sites\all\modules\similar\similar.module:2) in C:\User\web\WWW_ROOT_80\includes\common.inc on line 148.

This message tells you that there is something on line 2 in similar.module that is sent to the browser before the page is completed by Drupal and headers are sent (most likely it will be some other module in your case, I had an error in similar.module through my fault). This is your perpetrator.

PS: You might need to clear your cache (both browser and Drupal) to get the warning after disabling output buffering.

My site Maxi-Pedia

endless_wander’s picture

Anyone reading this, my problem having a blank line above the content of my feed ended up being caused by a blank line at the top of my index.php file. One more thing to check if this helps.

Bengtlueers’s picture

The template might also be an issue. In my case there were trailing spaces at the end of sites/all/themes/BRANDNAME/template.php.

cdmo’s picture

I found the culprit module using the technique described, ie

// from module.inc 
foreach (module_list(TRUE, $bootstrap) as $module) {
      drupal_load('module', $module);
      print $module.'|';

Nothing was wrong with the module though, no extra space, no closed PHP ?>. What I found worked, strangely enough, was SSHing into the remote server, and retyping just the the opening greater than sign using Vim, ie the < in <?php. Reload page. Valid XML. Crazy.

-cdmo

tefnut’s picture

I have tried the above, but it doesn't seem to be in the modules or theme, I notice the code on the site starts a line lower so whatever it is it's on every page and driving my client insane.

bsufan17’s picture

Thank you for the tip on the template.php file. That is where I found the problem, and probably never would have found it, had you not mentioned it.

boldart’s picture

Thanks y'all. There was an extra <?php declaration in the  template.php file which was adding 3 blank lines at the top of the XML output. Removed that from the template.php and everything is good. Thanks for posting.

Dharmendra.s’s picture

I resolved it by simply remove all the php closing tags ?> at the end of custom module files i.e .module file

tiger_h’s picture

In my Case it was the Rebuild theme registry and output template debugging on every page Option in a Zen Subtheme. Just switched it off

jnpwebdeveloper’s picture

This approach helped in my case:

If you are using phpstorm - or any other capable IDE - use regex search with the below snippet. In phpstorm simple use the "Find in Path" and search within your custom module directory.
^\s *<\?php

Use the "File mask" option to narrow down the search to *.module files. I found two modules that had a white space before the opening PHP tag causing the issue.

I hope this helps someone.

umeshpatil’s picture

Changing theme debug to false in settings.php solved this for me,

$conf['theme_debug'] = FALSE;