Recently took over an existing website that has Drupal 5 installed. Installed xmlsitemaps module, config setup, and when I view the file I get "error on line 5 at column 6: XML declaration allowed only at the start of the document". There are 5 lines of black space before doctype declaration.

I looked at page.tpl.php for whitespace above first line of code and found nothing. Looked elsewhere but can't find the culprit for this output.

Any direction or help would be graciously appreciated. Thank you.

Comments

john morahan’s picture

Look through the code files especially template.php and any custom modules for a closing ?> at the end followed by whitespace. This whitespace could be printed when the files are included. Remove the ?> to fix.

ddrohde01’s picture

Thank you for your reply. I downloaded all of my modules, did a global search for ?> and one by one removed any, then uploaded to test results. It didn't work. Where can I find the function that writes the template? There has to be something I am missing. Very frustrating.

Is there a way for me to echo to the source code what modules are being called when the page loads?

jaypan’s picture

All modules installed modules are loaded.

Look for any whitespace before opening php tags on all files.

Contact me to contract me for D7 -> D10/11 migrations.

ddrohde01’s picture

are you saying white space before all opening php tags in my module directory or everywhere?

There are over 50 modules in my modules directory. I did a global search in Dreamweaver for all ?> tags to look for instances. There were a few files that had the closing tags. I removed them, uploaded, and viewed source. No changes were reflected in my code.

It seem like there should be a logical way to determine what module is causing this rather than opening each page and looking for whitespace.

If I disable a module that has data stored will that data still be there when I re-enable the module? I am thinking I can turn off each module in the admin then check my source to determine which one is the culprit.

jaypan’s picture

All whitespace before the first PHP tag in each document in your modules and themes folder. Removing closing php tags is also important, but it appears you have already done that.

You should be able to disable all modules without losing any data, however to be sure you should back up your site first. I find the backup and migrate module is really good for that - reversions are very easy. For that matter, I'd disable them one at a time, check for whitespace, then after you are done revert the backup taken with that module anyways - just to be safe.

Contact me to contract me for D7 -> D10/11 migrations.

ddrohde01’s picture

I reviewed each name.module file in the entire site. I found a couple of closing ?> and removed them. That didn't fix the problem. I search for whitespace before the opening <?php tag as well and didn't locate anything. Any other ideas would be gratefully appreciated.

Thank you

jaypan’s picture

As you mentioned earlier, try disabling your modules one by one until you figure out what module the problem is in, then it will make it easier to track down the problem.

If you get through all the modules and the problem still is there, then try changing themes to see if it's in your theme.

Actually, on second thought, you would be better of checking your theme first, then the modules.

Contact me to contract me for D7 -> D10/11 migrations.

ddrohde01’s picture

Thanks for your advice. I haven't been able to track down the bug. I am running XMLsitemaps module too. The whitespace is being added before the doctype declaration in that module too. since the site map does not use a theme I think if I can figure out the order of operations for this process then I can locate the whitespace. Do you think that this whitespace could be coming from the template engine? Is that the bootstrap file?

This is the error I get on my sitemap page:

This page contains the following errors:

error on line 5 at column 6: XML declaration allowed only at the start of the document

The script generates the sitemap but there are 4 lines of whitespace before the doctype.

Thank you

jaypan’s picture

A general order of operations is that before doing any processing, Drupal compiles all .module files on the site, then starts doing any processing. I'm not sure when the theme files are compiled though.

I just checked the xmlsitemap module on my own site, and it's not adding any whitespace before the xml declaration, so I don't think it's that module.

Did you try disabling all modules one by one?

Contact me to contract me for D7 -> D10/11 migrations.

ddrohde01’s picture

I tried to disable all modules one by one, refresh source code, and the whitespace is still there.

The reason I was referring to the xmlsitemaps is because that module doesn't appear to load anything except for its respective code. Therefore, since that page is independent (at least in my mind) of other modules, then the source of my problem must be above the module framework.

I will keep poking around and let you know if I have success.

jaypan’s picture

All modules load all .module pages.

Try switching themes and see if that changes anything.

Contact me to contract me for D7 -> D10/11 migrations.

ddrohde01’s picture

Tried the theme swap. Same problem. Frustrating as hell. Appreciate all of your help.

jaypan’s picture

Strange. The next thing to try would be to update/replace all your Drupal core files.

Contact me to contract me for D7 -> D10/11 migrations.

john morahan’s picture

Just in case you haven't tried this already... have a look through your PHP error log for a warning like "Warning: Cannot modify header information - headers already sent by (output started at ..." if you find this, the "output started at" could be a clue as to which file/line is to blame

winternett’s picture

I got my XML sitemap module to work by removing this declaration <?xml version="1.0" encoding="UTF-8"?> entirely from xmlsitemap.xsl file in the XML Site Map (module) folder -

XML Sitemap Appears to be displaying fine now:

http://www.yoursite.com/sitemap.xml (example URL)

Apparently the encoding defaults if the encoding isn't specified.

I haven't fully unit tested this yet mind you.

Kate Hopkins’s picture

We had the same issue, and found an empty line AFTER closing the php ?> in our template.php. Since preprocess happens here, and it's a quick fix if this is what's causing the problem, I'd check here before disabling all of your modules.

jaypan’s picture

On that note you should not be using closing php tags in any files in drupal, with the exception of template files which contain PHP inside HTML. The reason for not using PHP tags in your files is because of the exact situation you faced - whitespace being sent to the browser before your doctype.

Contact me to contract me for D7 -> D10/11 migrations.

praveen.544@gmail.com’s picture

Hi All,

I am getting the white space problem before doc type declaration how i can sole this issue please help me because of this spaces i get the problem in webform report

Thanks&Reg.
praveen
praveen.544@gmail.com

jaypan’s picture

The solution is already posted in this thread.

Contact me to contract me for D7 -> D10/11 migrations.

praveen.544@gmail.com’s picture

Please can you help me where exactly i need to remove the spaces

WorldFallz’s picture

read the thread... as jay suggested. The answer is already here. Why should someone be more willing to help you than you are to help yourself?

praveen.544@gmail.com’s picture

Hi all we are useing webform_report modul in drupal for report generation in Report CSV Export while down loading excel sheet we get first 74 lines are empty please help me

rolodmonkey’s picture

praveen,

This is really a new request. Please add a new top-level forum topic, instead of continuing this thread.

--

Read more at iRolo.net