xml 描述和内容的区别:RSS2 中的编码标签

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7220670/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 14:54:46  来源:igfitidea点击:

Difference between description and content:encoded tags in RSS2

xmlrssfeedrss2

提问by Hamed Momeni

What is the difference, if any, between the <description>tag and the <content:encoded>tag in RSS 2.0 format specifications?

<description>标签和<content:encoded>RSS 2.0格式规范中的标签有什么区别(如果有的话)?

Is one more important than the other?

一个比另一个重要吗?

Should I be using both in my feeds or one will suffice?

我应该在我的提要中同时使用两者还是一个就足够了?

回答by random

The <description>tag is for the summary of the post, but in plain textonly. No markup.

<description>标签用于帖子的摘要,但仅限于纯文本。没有标记。

You can get around that if you escape the tags or wrap the content in:

如果您转义标签或将内容包装在:

<![CDATA[ post body goes <strong>here</strong> ]>

But you're not really supposed to be doing that.

你真的不应该这样做

If you want markup, you're supposed to use <content:encoded>and use the <![CDATA[and ]>wrappers here.

如果你想要标记,你应该在这里使用<content:encoded>和使用<![CDATA[]>包装器。

The content:encodedelement can be used in conjunction with the descriptionelement to provide an item's full content along with a shorter summary. Under this approach, the complete text of the item is presented in content:encodedand the summary in description.

RSS Best Practices Profile: content:encoded

所述content:encoded元件可以结合使用与所述description元件具有较短摘要一起提供一个项目的全部内容。在这种方法下,项目的完整文本在 中显示,content:encoded摘要在 中description

RSS 最佳实践配置文件:内容:编码

In short, <description>is for the summaryand the rest of the post is in <content:encoded>.

简而言之,<description>摘要,帖子的其余部分在<content:encoded>.

Since some readers may not support the tags as expected, you usually see the entire post in <description>and not a mix of the two.

由于某些读者可能不支持预期的标签,您通常会看到整篇文章,<description>而不是两者的混合。

回答by Dave Winer

The previous answer is incorrect.

之前的答案是错误的。

The RSS 2.0 specis very clear that you can encode the value of the <description> element.

RSS 2.0规范非常明确,您可以对 <description> 元素的值进行编码。

An item may also be complete in itself, if so, the description contains the text (entity-encoded HTML is allowed; see examples), and the link and title may be omitted. All elements of an item are optional, however at least one of title or description must be present.

一个项目本身也可能是完整的,如果是这样,描述包含文本(允许实体编码的 HTML;参见示例),并且可以省略链接和标题。项目的所有元素都是可选的,但必须至少存在标题或描述之一。

回答by Nicholas Petersen

The answer given by @random has some truth to it, but ultimately the situation is complex (if not confusing), as specified within the RSS 2.0 spec, when deciding how to handle descriptioninstead of / or at other times alongside of content:encoded.

@random 给出的答案有一定的道理,但最终情况是复杂的(如果不令人困惑),正如RSS 2.0 规范中所指定的那样,在决定如何处理description而不是 / 或在其他时间与content:encoded.

TLDR: When a content producer is willing to include BOTH a textual summary AS WELL as fuller content, then the situation is cleared up: Use descriptionfor the simpler textual summary, and content:encodedfor the fuller html content. But when they only want to include one of the two, only summary or only fuller content, then they are SUPPOSED to use the descriptiontag for this, in which case things remain ambiguous! A most unfortunate decision in my estimate, it means you HAVE to include fuller-html content to have clarity on this, otherwise, the descriptiontag is just as ambiguous as ever.

TLDR:当内容制作者愿意将文本摘要和更完整的内容都包含在内时,情况就清楚了:description用于更简单的文本摘要和content:encoded更完整的 html 内容。但是,当他们只想包含两者之一,仅包含摘要或仅更完整的内容时,他们应该为此使用description标签,在这种情况下,事情仍然不明确!根据我的估计,这是一个最不幸的决定,这意味着您必须包含更完整的 html 内容才能清楚地了解这一点,否则,description标签和以往一样模棱两可。

Publishers who don't want to employ itemsummaries in their feeds SHOULD use the descriptionelement for an item's full content rather than content:encodedbecause it has the widest support.

Publishers who employ summaries SHOULD store the summary in description and the full content in content:encoded, ordering descriptionfirst within the item. On items with no summary, the full content SHOULD be stored in description.

不想item在其提要中使用摘要的出版商应该将该description元素用于项目的完整内容,而不是content:encoded因为它具有最广泛的支持。

出版商谁雇用摘要应存储在描述摘要和完整内容content:encoded,命令description中的第一个item。在没有摘要的项目上,完整的内容应该存储在description.

One has to slow-cook meditate on what this all meant, but I thinkthese are the take-away points:

人们必须慢慢思考这一切意味着什么,但我认为这些是要点:

  1. If only one of these two tags is given, it MUST be the descriptiontag.
  2. That means content:encodedSHOULD NEVER exist without a descriptiontag placed alongside (and actually above) it.
  3. Unfortunately this means that when there is only one tag (which must be description), that the situation remains as ambiguous as ever: I.e. descriptioncontinues to be EITHER a simple textual summary, OR a fuller html content, you can't know!
  4. When BOTH are given, that's the only time the ambiguity is removed: Then descriptionshould be a simpler summary, and content:encodedwill container fuller html content.
  1. 如果只给出了这两个标签之一,它必须是description标签。
  2. 这意味着content:encoded如果没有description标签放在旁边(实际上是在上面),就不应该存在。
  3. 不幸的是,这意味着当只有一个标签(必须是description)时,情况仍然像以往一样模棱两可:即description继续是简单的文本摘要或更完整的 html 内容,您无法知道!
  4. 当给出 BOTH 时,这是唯一一次消除歧义:那么description应该是一个更简单的摘要,content:encoded并将包含更完整的 html 内容。

Or maybe I read this all wrong.

或者也许我读错了这一切。

Personally I think this decision was very unfortunate. They obviously did this to keep backwards compatibility, so readers at the time would be able to always have somedescription to read from (since content:encodedwas not yet supported, or not widely). But in so doing, they basically handicapped this. It's water under the bridge by now, but I think what they could have done, while getting the best of both worlds, was to add an attribute to descriptionlike: <description type="html | text">. So if <description type="text">(note they specify content:encodedis alwaysfor fuller html content) then it's specifying descriptionis just a simpler summary, and the producer does NOT have to also give full-content in-order for readers to know the type of this tag. While older readers would have just ignored this extra attribute. Water under the bridge, but we can dream.

我个人认为这个决定非常不幸。他们这样做显然是为了保持向后兼容性,所以当时的读者总能有一些描述可供阅读(因为content:encoded还没有支持,或者不广泛)。但这样做,他们基本上阻碍了这一点。现在是桥下的水,但我认为他们本可以做的,在两全其美的同时,添加一个属性来description喜欢:<description type="html | text">。所以如果<description type="text">(注意他们指定content:encoded总是更完整的 html 内容)那么它指定description只是一个更简单的总结,制作者不必为了让读者知道这个标签的类型而提供完整的内容。虽然年长的读者会忽略这个额外的属性。桥下有水,但我们可以做梦。

So as it stands, it seems to me everything is completely up in the air, **unless* BOTH tags are included, only then can you make the right assumptions.

因此,就目前而言,在我看来,一切都完全悬而未决,**除非*包含两个标签,只有这样您才能做出正确的假设。

P.S. As for the distinction between full content and summary content, see their original discussionon the descriptiontag.

PS至于full content和summary content的区别,看他们对tag的原讨论description