Rss20FeedFormatter Ignores TextSyndicationContent type for SyndicationItem.Summary

后端 未结 3 1646
梦毁少年i
梦毁少年i 2021-02-09 02:04

While using the Rss20FeedFormatter class in a WCF project, I was trying to wrap the content of my description elements with a section. I found t

3条回答
  •  一整个雨季
    2021-02-09 02:29

    I found the code for Cdata elsewhere

        public class CDataSyndicationContent : TextSyndicationContent
    {
        public CDataSyndicationContent(TextSyndicationContent content)
            : base(content)
        {
        }
    
        protected override void WriteContentsTo(System.Xml.XmlWriter writer)
        {
            writer.WriteCData(Text);
        }
    }
    

    Code to call it something along the lines:

    item.Content = new Helpers.CDataSyndicationContent(new TextSyndicationContent("TEST2", TextSyndicationContentKind.Html));
    

    However the "WriteContentsTo" function wasn't being called.

    Instead of Rss20FeedFormatter I tried Atom10FeedFormatter - and it worked! Obviously this gives Atom feed rather than traditional RSS - but worth mentioning.

    Output code is:

    //var formatter = new Rss20FeedFormatter(feed);
        Atom10FeedFormatter formatter = new Atom10FeedFormatter(feed);
        using (var writer = XmlWriter.Create(response.Output, new XmlWriterSettings { Indent = true }))
        {
            formatter.WriteTo(writer);
        }
    

提交回复
热议问题