Java ROME RSS库和RSS描述字段中的HTML代码
我需要在我的RSS提要中包含HTML代码。我使用Java罗马RSS库:
SyndFeed feed = new SyndFeedImpl();
feed.setFeedType("rss_2.0");
feed.setTitle("Title");
feed.setLink("example.com");
feed.setDescription("Description");
List<SyndEntry> entries = new ArrayList<>();
SyndEntryImpl entry = new SyndEntryImpl();
entry.setTitle("Name");
SyndContent syndContent = new SyndContentImpl();
syndContent.setType("text/html");
syndContent.setValue("<p>Hello, World !</p>");
entry.setDescription(syndContent);
entries.add(entry);
feed.setEntries(entries);
Writer writer = new FileWriter("rss.xml");
SyndFeedOutput output = new SyndFeedOutput();
output.output(feed, writer);
writer.close();
但输出XML包含编码描述:
<description><p>Hello, World !</p></description>
如何正确地将未编码的HTML代码包含在ROME中
# 1 楼答案
分析
根据RSS Best Practices Profile: 4.1.1.20.4 description的说法:
因此,电流输出是正确的
CDATA
编码如果希望有
CDATA
部分(CDATA
编码),可以使用以下代码段:其他参考资料
description
与content:encoded
根据RSS2.0规范,使用
description
元素就足够了:正如您所引用的那样。下面是一些例子:Encoding & item-level descriptions (RSS 2.0 at Harvard Law)有关更多详细信息,请参阅问题:Difference between description and content:encoded tags in RSS2 - Stack Overflow