Avoid Using "< [Cdata[ ]]>" in RSS
3 days ago
- #Web Development
- #RSS Feeds
- #XML Escaping
- Avoid using <![CDATA[ ... ]]> in RSS feeds as it requires splitting for the ]] character sequence, making code less readable and adding complexity.
- Using CDATA can mislead into thinking content is raw HTML or safer, but it's not, and it doesn't change the parsed value compared to normal escaping.
- Instead, use XML escaping with functions like xmlEscape to handle characters like &, <, >, ", and ' for simpler, more uniform output across RSS, Atom, and other contexts.
- While CDATA might reduce feed size by avoiding escapes, feeds are usually gzip-compressed, making repeated escape sequences compress well, and feed size is rarely a bottleneck compared to other web elements.
- For new code, ordinary XML escaping is recommended over CDATA due to its simplicity, uniformity, and avoidance of special edge cases, though existing libraries using CDATA are fine if necessary.