[英]CDATA section in RSS not working - rometools
I am using rometools for rss feeds. 我正在使用rometools作为rss提要。 I am trying to use html tags inside cdata in content section of the RSS item.
我正在尝试在RSS项的内容部分的cdata中使用html标记。 Here is my code:
这是我的代码:
public class RssView extends AbstractRssFeedView {
@Override
protected List<com.rometools.rome.feed.rss.Item> buildFeedItems(Map<String, Object> map,
HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) throws Exception {
List<Item> items = new ArrayList<>();
Object ob = map.get("feeds");
if (ob instanceof List){
for(int i = 0; i < ((List<?>)ob).size(); i++){
Object articleObj = ((List<?>) ob).get(i);
Article article = (Article)articleObj;
Item item = new Item();
item.setTitle(article.getTitle());
Guid guid = new Guid();
guid.setValue(item.getLink());
item.setGuid(guid);
item.setPubDate(article.getCreatedTime());
Description description = new Description();
description.setValue(article.getDescrition());
item.setDescription(description);
Content content = new Content();
content.setValue(buildContent(article));
item.setContent(content);
items.add(item);
}
}
return items;
}
@Override
protected void buildFeedMetadata(Map<String, Object> model, Channel channel,
HttpServletRequest request) {
channel.setTitle("Article");
channel.setLink("http://www.");
channel.setDescription("desciprtion");
channel.setLanguage("en-us");
}
private String buildContent(Article article) {
StringBuilder sb = new StringBuilder();
sb.append("<![CDATA[" +
"<!doctype html>\n]]>");
return sb.toString();
}
The problem is that html tags inside cdata that aren't supposed to be escaped are being escape. 问题在于,cdata中不应转义的html标签正在转义。
What you are trying to do, is not possible with Rome a the moment. 您正在尝试做的事,暂时无法在罗马实现。 See this issue: https://github.com/rometools/rome/issues/280
看到这个问题: https : //github.com/rometools/rome/issues/280
I ended up using 我最终使用
channel.setDescription(StringEscapeUtils.escapeXml11(getProblematicDescription()));
from 从
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.8.1</version>
</dependency>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.