Quantcast
Channel: .NET ServiceModel.Syndication - Changing Encoding on RSS Feed - Stack Overflow
Viewing all articles
Browse latest Browse all 2

.NET ServiceModel.Syndication - Changing Encoding on RSS Feed

$
0
0

I'm trying to solve a bug where all of the RSS feeds I'm producing at http://captainobvio.us produce the following error in Internet Explorer (versions 8 and 9):

Feed code error Switch from current encoding to specified encoding not supported. Line: 1 Character: 40

<?xml version="1.0" encoding="utf-16"?>

The issue is that the actual encoding type sent via the HTTP header is different than what the document declares. Here is what my code looks like for writing the feed's output to HTML:

public ContentResult Index()        {            var feed = _syndication.SyndicateIdeas(_repository.GetIdeas(0,15).Ideas);            var sb = new StringBuilder();            using (var writer = XmlWriter.Create(sb, new XmlWriterSettings { Encoding = Encoding.UTF8, NewLineHandling = NewLineHandling.Entitize, NewLineOnAttributes = true, Indent = true}))            {                feed.SaveAsRss20(writer);                writer.Close();            }            return Content(sb.ToString(), "application/rss+xml", Encoding.UTF8);        } 

And here is what my code looks like for actually building the feed, using System.ServiceModel.Syndication in .NET 4.0:

var feed = new SyndicationFeed("CaptainObvio.us - Recent Ideas","The most recent ideas posted by the Community on CaptainObvio.us", new Uri("http://captainobvio.us/"), "CaptainObvio.us", new DateTimeOffset(ideas[0].DatePosted), items)                           {                               Generator = "CaptainObvio.us - http://captainobvio.us/"                           };            return feed;

What I would like to do is change the XML document to read utf-8 instead of utf-16. I also checked the Encoding namespace to see if there was a UTF16 option (so I could correct the HTTP header instead of the XML document) and wasn't able to find one.

Is there an easy way change the encoding attribute on the XML document directly from System.ServiceModel.Syndication? What's the easiest way to fix this issue?


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>
<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596344.js" async> </script>