Problem/Motivation
I am using the latest update () of the module on a local development site and mirrored production site.
I have double checked all configuration and it is identical on both sites.
Visiting /sitemap.xml in the browser results in just that, a perfectly formed sitemap.
However, on the production site I see...

Digging deeper by looking into the page source, I can clearly see the offence! ...

On the production site, the sitemap itself if perfectly intact but that extra first line won't budge no matter how many attempts at regenerating the map Ido.
Any ideas anyone?
Thank you
| Comment | File | Size | Author |
|---|---|---|---|
| xml_sitemap_view_local_vs_production.jpg | 87.62 KB | sirclickalot | |
| xml_sitemap_view_on_production.jpg | 34.79 KB | sirclickalot |
Issue fork simple_sitemap-3560227
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
medha kumariWorking on It.
Comment #4
medha kumariHi, I create MR for this. Please check and review. Thanks!
Comment #5
sirclickalotHi @medha kumari,
Thank you for this.
Before I try it out though, could you please explain what you found to be the 'cause' of the problem and how your patch deals with that?
Comment #6
medha kumariHi @sirclickalot,
Thank you for your message and for looking into this.
The cause of the problem was that a blank line (or some invisible whitespace) was appearing before the XML declaration (<?xml version="1.0"?>) in the sitemap output. XML files must start with this declaration at the very top—if there’s anything before it, browsers and parsers will throw an error.
This extra blank line was coming from the function that generates the XML. Sometimes, it adds unwanted spaces or newlines at the start or end of the output.
The patch fixes this by using the trim() function, which removes any extra spaces or blank lines from the beginning and end of the XML before it’s saved or sent to the browser. This ensures the XML declaration is always at the very start of the file, so the sitemap is valid and the error goes away.
Hope this helps clarify things!
Comment #7
gbyteIt's not the generator, it's your environment. See issues like
...and a few more.
However as this happens again and again, I will look into working around it in the module.
Comment #8
gbyteComment #10
gbyteI have applied trimming to SitmeapWriter::outputMemory instead so custom plugins in the wild can take advantage.
Comment #12
sirclickalotGiven the 13000+ user base for this great little module coupled with impact of the fix in #10, might we be able to get a release out before Christmas?
Comment #13
gbyteI'm afraid this fix is relevant to a very small number of users with erroneous environments. The release will have to wait for further bug fixes and features.
Comment #14
sirclickalotComment #15
gbyte