Java ROME RSS库和RSS描述字段中的HTML代码

Java ROME RSS库和RSS描述字段中的HTML代码,java,rss,rome,Java,Rss,Rome,我需要在我的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<>();

我需要在我的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();
SyndFeed提要=新的SyndFeedImpl();
feed.setFeedType(“rss_2.0”);
feed.setTitle(“Title”);
setLink(“example.com”);
feed.setDescription(“Description”);
列表项=新的ArrayList();
SyndEntryImpl条目=新的SyndEntryImpl();
条目。设置标题(“名称”);
SyndContent SyndContent=新的SyndContentImpl();
setType(“text/html”);
setValue(“你好,世界!

”; entry.setDescription(syndContent); 条目。添加(条目); feed.setEntries(条目); Writer=newfilewriter(“rss.xml”); SyndFeedOutput=新的SyndFeedOutput(); 输出(feed,writer); writer.close();
但输出XML包含编码的描述:

菲罗,世界/P 如何正确地在ROME中包含未编码的HTML代码?

分析 根据报告:

描述必须适合作为HTML表示。HTML标记必须通过使用HTML实体
)或
CDATA
部分编码为字符数据

因此,电流输出是正确的

CDATA
编码 如果希望有
CDATA
部分(
CDATA
编码),可以使用以下代码段:

final List<String> contents = new ArrayList<>();
contents.add("<p>HTML content is here!</p>");

final ContentModule module = new ContentModuleImpl();
module.setEncodeds(contents);

entry.getModules().add(module);
final List contents=new ArrayList();
内容。添加(“HTML内容在这里!

”; final ContentModule=new ContentModuleImpl(); 模块.setEncodeds(内容); entry.getModules().add(模块);
其他参考资料
  • 说明
    内容:编码
    我应该在RSS提要项目中同时使用-
    description
    content:encoded
    节点,还是只使用其中一个节点

    那你呢

    项目本身也可能是完整的,如果是,则说明包含文本(允许实体编码的HTML;参见示例)

    根据RSS2.0规范,使用
    description
    元素就足够了:正如您所引用的那样。以下是示例:


    有关更多详细信息,请参阅问题:。

    谢谢您的回答。我应该在我的RSS提要项目中同时使用-description和content:encoded节点还是只使用其中一个节点?下面的情况如何:-
    一个项目本身也可能是完整的,如果是这样,说明中包含文本(允许使用实体编码的HTML;参见示例)
    ?罗马图书馆是否有机会将CDATA部分包含在描述字段中?如果是这样的话,请您再举一个例子。是的,它正在将名为
    的新节点添加到输出的RSS XML中,但我希望CDATA正好位于
    node@alexanoid对。我只能与您分享这些参考资料:和。