Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9045027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:08:40+00:00 2026-06-16T11:08:40+00:00

I have created a simple SyndicationFeed with many SyndicationItems. Each SyndicationItem has HtmlContent. The

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T11:08:43+00:00Added an answer on June 16, 2026 at 11:08 am

    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 a complete code example how to do this:

    using System;
    using System.Collections.Generic;
    using System.ServiceModel.Syndication;
    using System.Xml;
    
    namespace FeedProcessing
    {
        class FeedProcessing
        {
            static void Main(string[] args)
            {
                FeedProcessing fp = new FeedProcessing();
                fp.CreateFeed();
            }
            public void CreateFeed()
            {
                SyndicationFeed feed = new SyndicationFeed("Feed Title", "Feed Description", new Uri("http://Feed/Alternate/Link"), "FeedID", DateTime.Now);
                // Add a custom attribute.
                XmlQualifiedName xqName = new XmlQualifiedName("CustomAttribute");
                feed.AttributeExtensions.Add(xqName, "Value");
    
                SyndicationPerson sp = new SyndicationPerson("jesper@contoso.com", "Jesper Aaberg", "http://Jesper/Aaberg");
                feed.Authors.Add(sp);
    
                SyndicationCategory category = new SyndicationCategory("FeedCategory", "CategoryScheme", "CategoryLabel");
                feed.Categories.Add(category);
    
                feed.Contributors.Add(new SyndicationPerson("lene@contoso.com", "Lene Aaling", "http://lene/aaling"));
                feed.Copyright = new TextSyndicationContent("Copyright 2007");
                feed.Description = new TextSyndicationContent("This is a sample feed");
    
                // Add a custom element.
                XmlDocument doc = new XmlDocument();
                XmlElement feedElement = doc.CreateElement("CustomElement");
                feedElement.InnerText = "Some text";
                feed.ElementExtensions.Add(feedElement);
    
                feed.Generator = "Sample Code";
                feed.Id = "FeedID";
                feed.ImageUrl = new Uri("http://server/image.jpg");
    
                TextSyndicationContent textContent = new TextSyndicationContent("Some text content");
                SyndicationItem item = new SyndicationItem("Item Title", textContent, new Uri("http://server/items"), "ItemID", DateTime.Now);
    
                List<SyndicationItem> items = new List<SyndicationItem>();
                items.Add(item);
                feed.Items = items;
    
                feed.Language = "en-us";
                feed.LastUpdatedTime = DateTime.Now;
    
                SyndicationLink link = new SyndicationLink(new Uri("http://server/link"), "alternate", "Link Title", "text/html", 1000);
                feed.Links.Add(link);
    
                XmlWriter atomWriter = XmlWriter.Create("atom.xml");
                atomWriter.WriteProcessingInstruction("xml-stylesheet", 
                                                      "type='text/css' href='http://you.com/rss.css'");
                Atom10FeedFormatter atomFormatter = new Atom10FeedFormatter(feed);
                atomFormatter.WriteTo(atomWriter);
                atomWriter.Close();
    
                XmlWriter rssWriter = XmlWriter.Create("rss.xml");
                rssWriter.WriteProcessingInstruction("xml-stylesheet",
                                                     "type='text/css' href='http://you.com/rss.css'");
                Rss20FeedFormatter rssFormatter = new Rss20FeedFormatter(feed);
                rssFormatter.WriteTo(rssWriter);
                rssWriter.Close();
            }
        }
    }
    

    When this program is executed, two files are created:

    atom.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <?xml-stylesheet type='text/css' href='http://you.com/rss.css'?>
    <feed xml:lang="en-us" CustomAttribute="Value" xmlns="http://www.w3.org/2005/Atom">
        <title type="text">Feed Title</title>
        <subtitle type="text">This is a sample feed</subtitle>
        <id>FeedID</id>
        <rights type="text">Copyright 2007</rights>
        <updated>2012-12-28T19:50:18-08:00</updated>
        <category term="FeedCategory" label="CategoryLabel" scheme="CategoryScheme" />
        <logo>http://server/image.jpg</logo>
        <author>
            <name>Jesper Aaberg</name>
            <uri>http://Jesper/Aaberg</uri>
            <email>jesper@contoso.com</email>
        </author>
        <contributor>
            <name>Lene Aaling</name>
            <uri>http://lene/aaling</uri>
            <email>lene@contoso.com</email>
        </contributor>
        <generator>Sample Code</generator>
        <link rel="alternate" href="http://feed/Alternate/Link" />
        <link rel="alternate" type="text/html" title="Link Title" length="1000" href="http://server/link" />
        <CustomElement xmlns="">Some text</CustomElement>
        <entry>
            <id>ItemID</id>
            <title type="text">Item Title</title>
            <updated>2012-12-28T19:50:18-08:00</updated>
            <link rel="alternate" href="http://server/items" />
            <content type="text">Some text content</content>
        </entry>
    </feed>
    

    and rss.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <?xml-stylesheet type='text/css' href='http://you.com/rss.css'?>
    <rss xmlns:a10="http://www.w3.org/2005/Atom" version="2.0">
        <channel CustomAttribute="Value">
            <title>Feed Title</title>
            <link>http://feed/Alternate/Link</link>
            <description>This is a sample feed</description>
            <language>en-us</language>
            <copyright>Copyright 2007</copyright>
            <managingEditor>jesper@contoso.com</managingEditor>
            <lastBuildDate>Fri, 28 Dec 2012 19:50:18 -0800</lastBuildDate>
            <category domain="CategoryScheme">FeedCategory</category>
            <generator>Sample Code</generator>
            <a10:contributor>
                <a10:name>Lene Aaling</a10:name>
                <a10:uri>http://lene/aaling</a10:uri>
                <a10:email>lene@contoso.com</a10:email>
            </a10:contributor>
            <image>
                <url>http://server/image.jpg</url>
                <title>Feed Title</title>
                <link>http://feed/Alternate/Link</link>
            </image>
            <a10:id>FeedID</a10:id>
            <a10:link rel="alternate" type="text/html" title="Link Title" length="1000" href="http://server/link" />
            <CustomElement>Some text</CustomElement>
            <item>
                <guid isPermaLink="false">ItemID</guid>
                <link>http://server/items</link>
                <title>Item Title</title>
                <description>Some text content</description>
                <a10:updated>2012-12-28T19:50:18-08:00</a10:updated>
            </item>
        </channel>
    </rss>
    

    Explanation:

    Whenever the XmlWriter instance is created, but before calling either:

    atomFormatter.WriteTo(atomWriter);
    

    or:

    rssFormatter.WriteTo(rssWriter);
    

    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'").

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Could someone help me on this, i have created simple webservices and it has
I have created a simple site that reads a database table and displays it
Could someone help me on this, I have created simple web services using axis2
I have created this simple program to learn shared_ptr using namespace std; #define Yes
I have created simple application in windows sharepoint services. Now I want to deploy
I have created a simple table and i need to position. does anyone have
I have created a simple command line tool that outputs hello world. This is
I have created a simple class called Engine which has an ivar called inputName
I have created simple chat application using smack api.i can able to chat well.but
I have created a simple bean using this example from Per http://per.lausten.dk/blog/2012/02/creating-your-first-managed-bean-for-xpages.html And I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.