SyndicationFeed: Content as CDATA?

前端 未结 9 2068
梦毁少年i
梦毁少年i 2021-01-13 16:17

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)

相关标签:
9条回答
  • 2021-01-13 16:56

    I had the same problem as some where the WriteContentsTo override wasn't being called in cpowers example (still no idea why). So, I changed it to inherit from the SyndicationContent class instead. Not sure if this is the best solution, but worked great in my situation.

    public class CDataSyndicationContent : SyndicationContent
    {
        public CDataSyndicationContent(string content)
        {
            Text = content;
        }
    
        public override SyndicationContent Clone()
        {
            return new CDataSyndicationContent(Text);
        }
    
        public override string Type
        {
            get { return "html"; }
        }
    
        public string Text { get; private set; }
    
        protected override void WriteContentsTo(XmlWriter writer)
        {
            writer.WriteCData(Text);
        }
    }
    
    0 讨论(0)
  • 2021-01-13 16:57

    try this

    XmlReaderSettings settings = new XmlReaderSettings();
                settings.IgnoreComments = false;
                //settings.ProhibitDtd = false;
                using (XmlReader reader = XmlReader.Create(rssurl, settings))
    
    0 讨论(0)
  • 2021-01-13 16:59

    try

    item.Content = "<![CDATA[" + 
                SyndicationContent.CreateHtmlContent("<b>Item Content</b>") + "]]>";
    
    0 讨论(0)
提交回复
热议问题