asp.net – SyndicationFeed:内容为CDATA?

我正在使用.NET的SyndicationFeed来创建RSS和ATOM提要.不幸的是,我需要在描述元素(SyndicationItem的Content属性)中使用 HTML内容,格式化程序会自动HTML进行编码,但我宁愿将整个描述元素包装在CDATA中,而不对HTML进行编码.

我的(简单)代码

var Feed = new SyndicationFeed("Title","Description",new Uri("http://someuri.com"));
var items = new List<SyndicationItem>();

var item = new SyndicationItem("Item Title",(string)null,new Uri("http://someitemuri.com"));

item.Content = SyndicationContent.CreateHtmlContent("<b>Item Content</b>");

items.Add(item);
Feed.Items = items;

有人知道如何使用SyndicationFeed做到这一点吗?我的最后一招是“手动”为Feed创建XML,但我宁愿使用内置的SyndicationFeed.

解决方法

这对我有用:

public class CDataSyndicationContent : TextSyndicationContent
{
    public CDataSyndicationContent(TextSyndicationContent content)
        : base(content)
    {}

    protected override void  WriteContentsTo(System.Xml.XmlWriter writer)
    {
        writer.WriteCData(Text);
    }
}

然后你可以:

new CDataSyndicationContent(new TextSyndicationContent(content,TextSyndicationContentKind.Html))

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....