WordPress RSS Feed Fix: XML Parsing Error
The other day I encountered “XML Parsing Error: XML or Text Declaration Not at Start of Entity” error when I accessed Globinch blog RSS Feed. Till the previous day everything was OK. Because of this error Globinch Feedburner feed got problems and was not delivering the daily updates to the readers. It took me almost 12 hours to fix this.
Why : XML Parsing Error: XML or Text Declaration Not at Start of Entity
In a well formed XML the XML Prolog (starts with “<?xml … ?>”), if present, should be the first entry of the file. There should not be any blank line before the XML Prolog. So if you have a blank line just before the “<?xml version=”1.0″ encoding=”UTF-8″?>” You will encounter the above error. See the screen shot below.
I searched many blogs and discussion forums. Most of them suggested to check the “wp-includes/feed-*” files for blank lines. I checked all those files and uploaded if necessary. Some blogs suggested to add some scripts which will remove the new line and tab characters from the generated string. I tried all these but the RSS error was still there.
Fix for XML Parsing Error
The question is who or which script file is introducing the blank line in the RSS XML? Unfortunately it is very easy to introduce that bug in PHP. If any of your PHP file (may not be directly related to feed) has a blank line before or after (outside) bracketed sections (<?php and after ?>) causes the issue.
This can introduce the blank line in the feed RSS.
1. Using WordPress plug-ins
- Download the plugin from above download link.
- Unzip and upload it to /wp-content/plugins directory.
- Change the permission of your all .php files to “777” for time being.This will help the plugin to remove the blank lines from the files if the files are writable.
- Go to your dashboard and activate the plugin and follow the instructions to scan the files and to fix the blank lines.
- Once the process is over change the permission of all the .php files back to the original (“755”).
I tried this solution, unfortunately in my case this plugin didn’t help me. It did removed many spaces in many .php files but the RSS error was still there.
2. Deactivate your plug-ins one by one
This is the second step I tried. It was suggested in many blogs and forums. I deactivated each plugin and checked and activated them again. But this procedure also did not help me.
3. Check your files manually.The final solution
Finally I tried another approach. I sorted all my .php files which I had changed in the last two days. I found that only one file I changed, It was functions.php in my themes folder. I check for blank lines, there were none. Finally I found that there is a space after one “?> “ php close tag. Removed it and uploaded the file using FTP. Checked the RSS Feed. It was perfect!
So you can try all these options. Find out the PHP files which you changed just before you encountered this error and remove any blank lines or space in that file before .