哪种编码更适合RSS的HTML? [英] Which is better for encoding HTML for RSS?

查看:88
本文介绍了哪种编码更适合RSS的HTML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近将HTML引入了一些我发布的RSS feed中(到目前为止,只有纯文本,没有标记),我想知道哪种方法更好:使用字符编码(例如htmlspecialchars)或将所有内容封装在CDATA?

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?

在我看来,CDATA可能会更容易,但是我不清楚选择某种方法与选择是否有任何理由(微妙或其他)另一个。 (对于初学者来说,在查看源代码时,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...)

推荐答案

CDATA适用于任何XML解析器不应解析。 XML解析器将解析不在CDATA块中的所有标记 ,它们可能具有不同的含义。

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也会产生开销如果不需要解析器的话。

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.

那是说,我确实同意jamesh,在那一点上,尽量避免在您知道不会使用HTML或其他方式的情况下避免CDATA块。您应该始终偏爱Atom而不是RSS。我产生了一个提要阅读器,并且在抓取提要时,总是喜欢Atom而不是RSS。

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.

这篇关于哪种编码更适合RSS的HTML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆