Sitemap Encoding Errors: UTF-8, Special Characters and Escaping
Short answer: a sitemap must be saved as UTF-8, special XML characters must be escaped (& becomes &), and URLs with spaces, accents or non-Latin letters must be percent-encoded. When one of these is wrong, Search Console usually reports a parsing error or an invalid URL. Fix it in whatever writes the sitemap, then resubmit.
The three rules
1. The file is UTF-8
Google’s docs say plainly: “The sitemap file must be UTF-8 encoded.” Declare it on the first line and make sure the file really is UTF-8. A file saved as Windows-1252 or Latin-1 with an accented character inside is not valid UTF-8, even if the first line says it is.
<?xml version="1.0" encoding="UTF-8"?>
2. XML special characters are escaped
| Character | Write it as |
|---|---|
& | & |
' | ' |
" | " |
> | > |
< | < |
The & in query strings is the one that breaks most sitemaps.
3. URLs are percent-encoded
The sitemaps.org protocol says URLs must be escaped the way the web expects. A space becomes %20, and letters outside basic Latin are written as their UTF-8 bytes in percent form:
Readable: https://example.com/café/menü In sitemap: https://example.com/caf%C3%A9/men%C3%BC
Google crawls the URLs as written, so list the exact form your site serves and links to. If your pages use percent-encoded links, the sitemap should match.
How to check your file
curl -s https://example.com/sitemap.xml -o sitemap.xml file sitemap.xml # should say UTF-8 (or ASCII) iconv -f UTF-8 -t UTF-8 sitemap.xml > /dev/null && echo "valid UTF-8" grep -n '&' sitemap.xml | grep -vE '&(amp|lt|gt|quot|apos|#[0-9]+);' | head # raw & grep -o '<loc>[^<]*' sitemap.xml | grep ' ' | head # spaces inside URLs
A byte order mark (three invisible bytes at the start) can also trip the parser. Save files as “UTF-8 without BOM”.
Where encoding errors come from
- String-built XML. Code that glues strings together without escaping. Use an XML library, or escape every value.
- Database or export in another encoding. Titles or slugs stored as Latin-1 get written into a UTF-8 file.
- Editing by hand in an editor that saves in a local encoding or adds a BOM.
- Unencoded slugs from a CMS that allows spaces or accents in URLs.
After fixing, validate the file and resubmit it in Search Console’s Sitemaps report. The free sitemap checker confirms the file is a real sitemap and tests 30 of its URLs live.
Frequently asked questions
What encoding must a sitemap use?
UTF-8. Google’s sitemap docs say the file must be UTF-8 encoded, and the sitemaps.org protocol says the same.
Can my sitemap contain non-English URLs?
Yes. Write them percent-encoded (for example /caf%C3%A9 for /café), the same way a browser sends them. Use the exact form your site serves, so the URL in the sitemap matches the page.
Why does a URL with & break my sitemap?
Inside XML, & must be written as &. A raw & makes the file invalid, and Search Console reports a parsing error.
What is a byte order mark (BOM)?
Three invisible bytes some editors add at the start of a UTF-8 file. Before <?xml they can make Search Console report leading whitespace or a parsing error. Save the file as "UTF-8 without BOM".