SyndicationFeed:内容CDATA? [英] SyndicationFeed: Content as CDATA?

查看:209
本文介绍了SyndicationFeed:内容CDATA?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用.NET的SyndicationFeed创建RSS和Atom提要。不幸的是,我需要在描述元素的HTML内容(SyndicationItem的内容属性)和连接codeS的HTML自动格式化,但我宁愿有包裹在CDATA没有编码的HTML整个description元素。

I'm using .NET's SyndicationFeed to create RSS and ATOM feeds. Unfortunately, I need HTML content in the description element (the Content property of the SyndicationItem) and the formatter automatically encodes the HTML, but I'd rather have the entire description element wrapped in CDATA without encoding the HTML.

我的(简单)code:

My (simple) code:

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?我的最后一招是手工创建用于饲料的XML,但我宁愿使用内置的SyndicationFeed。

Anybody an idea how I can do this using SyndicationFeed? My last resort is to "manually" create the XML for the feeds, but I'd rather use the built-in 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))

这篇关于SyndicationFeed:内容CDATA?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆