I have created a simple SyndicationFeed with many SyndicationItems. Each SyndicationItem has HtmlContent. The HtmlContent is a table. This displays OK, but now I need a minimum of styling/padding on the table. I believe I need to add a stylesheet reference like
<?xml-stylesheet type="text/css" href="http://you.com/rss.css" ?>
But I do not see how to do this with the .NET 4.5 SyndicationFeed or Atom10FeedFormatter classes.
Here is the (pseudo) code that is generated by a WCF service.
var feed = new feed(......);
var xqn = new XmlQualifiedName( "mysys" , "http://www.w3.org/2000/xmlns/" );
feed.AttributeExtensions.Add( xqn , myuri );
feed.ElementExtensions.Add( "creator" , "sys" , teaminfo );
feed.Authors.Add( new SyndicationPerson( emailaddr) );
feed.Categories.Add( new SyndicationCategory( mycategory ) );
feed.Description = new TextSyndicationContent( feedDesc );
feed.Copyright = SyndicationContent.CreatePlaintextContent(copyr);
feed.Language = "en-us";
feed.ImageUrl = new Uri( myuri + "/logo" );
var dbitems = GetListFromDb(key);
var syndItems = new List<synitem>();
foreach (var item in dbitems)
{
var htmlContent =
SyndicationContent.CreateHtmlContent( MakeHtmlFromStuff(item) );
var itemUri = new Uri( myuri + itemuri );
var synitem = new synitem( item.code , htmlContent , itemUri , item.key , DateTimeOffset.UtcNow );
syndItems.Add( synitem);
}
feed.Items = syndItems;
return new Atom10FeedFormatter(feed);
Hopefully not missing something obvious. All ideas appreciated.
Thanks.
Here is a complete code example how to do this:
When this program is executed, two files are created:
atom.xml:
and rss.xml:
Explanation:
Whenever the
XmlWriter
instance is created, but before calling either:or:
call the
WriteProcessingInstruction()
method on the respective XmlWriter instance, passing to it the two required parameters -- the name of the PI (in this case"xml-stylesheet"
) and the text of the PI (in this case"type='text/css' href='http://you.com/rss.css'"
).