views:

567

answers:

7

This is something I've been wondering for a while now. I'll occasionally come across an RSS feed that is broken, and blown to pieces all because line 23 say "Sanford & Sons." The most confusing thing is the fact that if you convert the & into &, all is well, even though your alternative still contains the problem-char!

Please somebody explain this confusing mystery to me.

+4  A: 

Because it must be escaped in XML syntax. Same reason here.

http://myst-technology.com/public/item/11878

Ed Swangren
+2  A: 

When a 'raw' & is seen, the interpreter is looking for one of the valid escaped & sequences (such as '&' ). When a valid sequence is found found it throws an error. That's all there is to it.

Mitch Wheat
Yes, but why? :)
Jonathan Sampson
..because of the XML specification
Ed Swangren
This is no different than asking why you can't use raw < and > in XML text
ironfroggy
There's really no further answer for you to seek.
Dustin Fineout
Jonathan Sampson
+1  A: 

This depends highly on the RSS client, but most likely it's attempting to XML-decode the contents (in your example "Sanford & Sons"). When that happens, & indicates an escaped character. If you don't use &amp; as it decodes, it will try to use the next few characters to complete the escape sequence. Odds are highly likely that it will fail.

Randolpho
A: 

Because RSS is XML, and XML demands certain characters be escaped, such as the ampersand.

Svend
+4  A: 

Because & signifies the start of an xml entity. The parser is expecting something else there.

You could argue that it should be smart enough to know that the ampersand in "Sanford & Sons" is just an ampersand. But what about when you really want to show ampersand with text? Is "&pc; some custom (also invalid) entity, or should it interpret that as an ampersand also? What about "&amp;amp;"?

Joel Coehoorn
A: 
Boldewyn
A: 

Not sure if this helps but when I needed to solve this problem I used the numeric entity ref for an ampersand which is & Running this through the w3c validator passed so I guess it's ok to use this.

Cheers

slarti42uk