Blank spaces opening RSS XML file - How to solve? All of the sudden, we are experiencing problems with our RSS feed which comes with the Drupal core 7.x . It is no longer valid due to two spaces before the opening XML tag. The following error is what I get in the feed validator:


  line 1, column 2: XML parsing error: &lt;unknown>:1:2: XML or text declaration not at start of entity


So I am aware of other related posts on Stack Exchange and tried the things mentioned in:


Approach to removing extra space at beginning of RSS file?
xml sitemap module : XML declaration allowed only at the start of the document [closed]
RSS Feed does not validate using Views RSS module


These are the things we did do so far:


Checked all PHP-files on the website for containing blank spaces before the opening tags. There were a few, we fixed them all but no help.
Changed the default theme to another theme, making sure it is not theme related.
When I create a custom RSS feed with Views, the same two blank spaces show up before the XML opening tag.
I checked every page, block and view that has manually written PHP tags everywhere and deleted every space that could cause this.
All modules and Drupal core is updated to the most recent versions.
I checked on the Drupal forum for related issues in XML Sitemap, Metatag, RDF, Schema.org (modules we are using) with no success. I disabled every one of the above mentioned modules one by one, but with no success.
Eventually we exported the complete website, except the sites/default/files/ folder which contains no PHP files anyway, and imported it local. The blank spaces are gone in the local setup.


What makes it a bit difficult too, is that I have no idea when the RSS feed went broken. It can be between a week and a few months, making it difficult to filter out when I updated some contrib modules.  

So we are quite desperate in finding this, especially since the problem doesn't exist in a local setup. We have a news website so having a working RSS feed is pretty important. 

We must be overlooking something, but have no idea what it can be.
Some more troubleshooting ideas:


Do the spaces only appear on the RSS page, or also on other pages? That could tell you whether the problem is in a central place or a template/include-file that is only loaded for the RSS feed.
You can use var_dump(get_included_files()) (ideally in the template, just before the XML is generated) to see a list of all PHP files that have been included so far. This might help with investigating - look for closing PHP tags at the end of the files, print statements, etc.


Also, an idea for a dirty workaround (may cause other problems, but could be worth a try if it's urgent): ob_start() buffers all output, while ob_end_clean() deletes it. So if you put an ob_start() in the top of your index.php and an ob_end_clean() at the start of the RSS template, this might let you discard the spaces. (It shouldn't affect anything else, because the buffer is flushed automatically if it's still open when the script ends.)