Which is better for encoding HTML for RSS?

北战南征 提交于 2019-12-04 12:19:47

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.

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

At the risk of giving you the answer you may not want to hear: use Atom instead of RSS.

Atom is nicely namespaced XML, so you can mix and match XHTML right in, without having to worry about the encoding issue you ask about.

It's pretty much supported everywhere RSS is, and because it's just vanilla Atom, it's easier to roll your own if you really don't want to use a library to manipulate it.

Atom is also a IETF standard, which RSS isn't.

htmlentities() works like a charm. No need to use CDATA. http://php.net/manual/en/function.htmlentities.php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!