I am trying to get the raw string of the RSS xml. I tried the below but my string builder ends up blank. What is the correct way to do this?

var rssFormatter = new Rss20FeedFormatter(feed, false);
var output = new StringBuilder();
using (var writer = XmlWriter.Create(output, new XmlWriterSettings { Indent = true }))
{
    rssFormatter.WriteTo(writer);
    return output;
}
有帮助吗?

解决方案

You probably want to flush your writer...

var rssFormatter = new Rss20FeedFormatter(feed, false);
var output = new StringBuilder();
using (var writer = XmlWriter.Create(output, new XmlWriterSettings { Indent = true }))
{
    rssFormatter.WriteTo(writer);
    writer.Flush();
    return output;
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top