Problem: When I view my GooglebaseXML feed it shows an error like the following (the exact message will depend on your browser):

XML Parsing Error: XML or text declaration not at start of entity
Location: http://www.mysite.com/index.php?option=com_googlebasexml&format=xml&country=GB
Line Number 2, Column 1:<?xml version="1.0" encoding="UTF-8" ?>
^

Solution: The error in your XML feed is usually caused by your template or a system plugin inserting an empty space at the start of the XML document. Unfortunately the specification for an XML document is very precise and this is not allowed: the <xml> tag must be the very first thing in the document.

If you go to your site index.php page and look at the page source you will probably see that there is also an empty space or line inserted at the start of the html document, by the same plugin, strictly this makes the html invalid but web browsers just deal with this sort of thing.

The GooglebaseXML advanced options contain an option called 'Clean Output Buffer', make sure that this is turned on. The feed will then attempt to clear any previous output from the output buffer. Usually this will be enough to fix the problem.

If this does not work unfortunately there is no alternative to find out what is generating the extra output - it is not generated by the feed.The way to solve this is to try temporarily disabling each of your active plugins in turn, and seeing if the error goes away. The problem is not caused by any of the Joomla core plugins, it will be a third party one that is responsible. Also it seems to be only system plugins that cause this problem, so you can narrow your search to 3rd party system plugins. Occasionally it can be a problem with your site index.php file if this has been edited, but this is more rare.

Once you have the offending culprit you are welcome to send it to us and we will help remove the problem, it is usually just an empty space outside <?php> tags that cause the problem so it is easy to fix.

Related Issues

Note that leaving your site error reporting turned on can also create a similar problem, if anything happens to generate a PHP warning it will be inserted into the output, invalidating the XML. The solution in this case is to turn the level of your error reporting to 'none' in your Joomla configuration - which is the only safe level anyway on a live site.

There is also a plugin called mainpage that forces the component output inside a div tag, this obviously causes problem for XML output. To solve this you need to edit the mainpage plugin, find line 22 in mainpage.php:-

if (@$_REQUEST['format'] != 'raw') {

change this to

if (@$_REQUEST['format'] != 'raw' && @$_REQUEST['format'] != 'xml') {