Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
XML is including 2 spaces at the start of the file
Example URL :
The XML output is including 2 spaces at the start of the file :
<?xml version="1.0" encoding="utf-8"?>
--^
The XML is still present, error is thrown when you attempt to view it via a browser or other XML viewer. The issue is also intermittent.
Steps to reproduce :
- Visit your endpoint URL and generally the error will occur
- If not add the .xml
To get rid of the issue :
- Change .xml to .json
- Change .json to .xml (or leave blank)
Remove additional spaces where they are located
Essentially some spaces have found there way in where they shouldn't be. I've had a look through but can't seem to locate them.
Find and remove spaces
Locating the additional spaces and removing them.
Comments
Comment #1
marcingy CreditAttribution: marcingy commentedPlease provide clear steps to reproduce or provide a simple test that clearly shows the bug given this statement - The issue is also intermittent
Comment #2
mikeefreedom CreditAttribution: mikeefreedom commentedHi Marcingy,
I can't post a link to our example as it's a staging site I'm unable to share publicly. However I could email a link and access to you.
As for reproducing the intermittent issue... Another dev has tested the URL 10 times and couldn't reproduce it. Then every 4th or 5th time it would occur.
On my machine it would happen more often than not - both using the same URL served from the same server.
My other dev has also noticed that occasionally opening XML tags are missing the first < e.g.
<uuid>2ad272f3-675e-2c34-ed3a-6570ac92db02</uuid>
Would sometimes be :
uuid>2ad272f3-675e-2c34-ed3a-6570ac92db02</uuid>
Again, steps to successfully reproduce this were pretty much hit refresh until it occurs. Then upon the next refresh is was back to normal.
Let me know how I can send this URL and access details to you and you will be able to see a live example. I'm happy to post my custom module code as well.
Comment #3
mikeefreedom CreditAttribution: mikeefreedom commentedWe thought the UUID module might not be playing nicely but dropping that out had no effect - gutted.
Comment #4
marcingy CreditAttribution: marcingy commentedThe best bet sounds like if you can supply the custom code to start with as that might give us some ideas, well there goes my initial suggestion of try disabling the uuid module :(
Also if you could post a copy of your endpoint export that would be great feel free to rename anything that might compromise your site as this will help us in debuging.
Comment #5
mikeefreedom CreditAttribution: mikeefreedom commentedHave you got a BitBucket account? We can provide you access to the repo.
It has both the custom code and the exported endpoint on it. We're happy for you to look at it, just not the rest of the public :)
Comment #6
kylebrowning CreditAttribution: kylebrowning commentedThis isn't something service sis doing, this is something a module on your system is doing.
run this ruby script and find the culprit
Comment #7
mikeefreedom CreditAttribution: mikeefreedom commentedSorry for delay.
We've run this test and come back with 3 template files that are unrelated. We're running tests as we speak.
Will this Ruby RegExp check for spaces at the start and end of a file? My RegExp is a bit rusty.
And thank you for providing it :)
Comment #8
Mo Omar CreditAttribution: Mo Omar commentedHi,
I am sorry but I don't understand anything in this page. I just want to know if my sitemapxml is working or not. Here is a link to my sitemap
When I click on that link, it gives me different pages on different browsers.
On FF, I get this message: "
XML Parsing Error: XML or text declaration not at start of entity
Location: https://twelvestepjournaling.com/sitemap.xsl
Line Number 2, Column 1:<?xml version="1.0" encoding="UTF-8"?>
^
"
When I click edit sitemap from admin side, i get this message: There are currently no XML sitemap contexts available.
Would any of you experts tell me if my sitemap is working or not? Thank you very much!!
Comment #9
ch@it@li CreditAttribution: ch@it@li commentedHello,
I have same issue.
Please provide me solution.
Thanks
Comment #10
marcingy CreditAttribution: marcingy commented@ch@it@li the issue is nothing to do with services the issue lies somewhere in your code base outside services
Comment #11
jamatulli CreditAttribution: jamatulli commentedThis issue is a bit too common and does usually show up with XML docs. Someone probably left a space at the beginning of a module.
[space]<?php
You can either try to find that bit of code with some tool or command OR put this in includes/bootstrap.inc at line 1112:
echo $filename;
The line number could change subject to updates to Drupal 7 so make sure it is inside the drupal_load function:
Look at the source code for the page (right click on the page and "view source") and you will see a long list of the modules being loaded all run together. The space will be right after the file with the problem. Find that file, open it up and delete the space at the beginning.
Comment #12
yareckon CreditAttribution: yareckon commentedjamatulli, thank you! That's a great trick! Your comment is worth its weight in gold.
Comment #13
sarathkmHere is another way of using grep to find the culprit. Mostly it is module file so...
grep -R -H '^ <?php' modules/**/*.module
This will check all module files withing your module folder ( i am a step back in my sites/all folder in my linux terminal to find culprit.)
If you find two spaces leave two space between ^ and <?php, if one space leave one.
you will get the path of file which is culprit.
If you just get the filename you can find its path via
locate -br 'culprit.module'
After correcting clear cache. :)
Regards To All
Comment #14
jamatulli CreditAttribution: jamatulli commentedVery nice. Grep is required but that is fine for all the *nix users.
Could do this as well to catch any number of spaces.
grep -R -H '^[[:space:]]*<?php' *.module
Comment #15
sarathkmThat is more refined form for finding space. I guess grep is available in Mac OS too.
While for windows we can use findstr in place of grep to find the culprit.
I guess it will go something like this
findstr "^ *<?php" *.module
There is a space between ^ and * so as to match any number of spaces at start of line. Will search all .module files in current and subdirectories with matching pattern.
Or
findstr /b " *<?php" *.module
It will match the pattern at the beginning of line with one or more spaces
findstr Reference
Could try for grep like this too
grep -R -H '^ *<?php' modules/**/*.module