Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

Simple question, I'm asking just to make sure.

A Google sitemap generator generated a sitemap.txt fle with links written like this:

http://www.domain.com/category.htm?name=some-name&cat_id=8

is it correct to use the & in these links in place of the & or it's just an error made by the sitemap generator?

Thanks.

share|improve this question
add comment

4 Answers

up vote 6 down vote accepted

That is correct. It is the HTML entity for an ampersand (&) and is the proper character representation of it in a properly encoded URL. Ampersands (&) and well as < and > are special characters in XML and HTML and need to be displayed using their special character entities.

share|improve this answer
    
Are you sure all ampersands have to be entity-escaped? I thought that was only for those separating parameters in query strings. I've always escaped ampersands within file or folder names or in the parameters themselves using percent-encoding (%26): e.g. http://foo/a%26r.php?foo=1&amp;genre=r%26b –  Lèse majesté Oct 21 '10 at 19:37
    
I'm not sure about percent-encoding is valid or not so I can't say for sure. –  John Conde Oct 21 '10 at 19:48
    
@Lèse - because it's an XML document it has to be escaped, unless you use a CDATA node (just noticed that bdadam said the same thing, but much earlier than me) –  Mark Henderson Oct 26 '10 at 20:30
    
> don't strictly need to be entity encoded in XML. –  w3d Feb 20 at 12:57
add comment

Your Sitemap file must be UTF-8 encoded (you can generally do this when you save the file). As with all XML files, any data values (including URLs) must use entity escape codes for the characters.

This may help out, http://sitemaps.org/protocol.php

share|improve this answer
add comment

sorry I'm new here, and don't have enough reps to comment on the comment of Lèse majesté. So here it is as an answer:

URL-Encoding and XML entity encoding are not the same things. You need URL-Encoding to replace special characters in URLs, such as & which can only be used for the separation of query parameters. XML entity encoding is for encoding special characters in XML (also XHTML). This means, if you have a URL in an XML (or XHTML) file, and this URL includes some & characters, you have to entity encode it to &amp;. So in a sitemap.xml you will have urls like in the question from Marco Demaio.

Cheers,

Adam

share|improve this answer
add comment

You can also convince yourself by checking

You can't really argue against the official xml sitemaps protocol page :)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.