Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which is better for encoding HTML for RSS?

Tags:

php

cdata

rss

I recently introduced HTML into some RSS feeds that I publish (which up to now only had plain text, no markup), and I was wondering which method is better: use character encoding (such as htmlspecialchars) or just encapsulate everything in CDATA?

It seems to me that CDATA might be easier, but I'm unclear as to whether there might be any reasons (subtle or otherwise) for choosing one approach versus the other. (For starters, the CDATA approach would be easier to read when viewing source...)

like image 279
Novaktually Avatar asked Mar 01 '23 05:03

Novaktually


2 Answers

CDATA is for any data that should not be parsed by the XML parser. Any tags not in a CDATA block will be parsed by the XML parser and may take on a different meaning.

CDATA can also incur an overhead for the parsers if there is no need for it. Try to avoid CDATA blocks any time you know HTML (or otherwise) won't be used, otherwise use it.

That said, I do agree with jamesh, in that you should always prefer Atom over RSS. I produce a feed reader and when scraping feeds, always prefer Atom over RSS.

like image 170
Ryan McCue Avatar answered Mar 05 '23 19:03

Ryan McCue


Personally CDATA is easier, as it allows the display of the actual HTML by the subscriber without their reader needing to do anything funny.

If you use HTML Encoding, the subscribers reader, or website iteself, must decode the source to display the HTML

like image 39
Mitchel Sellers Avatar answered Mar 05 '23 19:03

Mitchel Sellers