Found a solution.
I can add an item to the feed like this:
var contentItem = new SyndicationItem("title", "description", new Uri("http://myuri.com"));
and then add custom elements to this like this:
contentItem.ElementExtensions.Add("customElement", String.Empty, "text inside my custom element");
If I want to add a custom element and add custom attributes to it; I can do:
contentItem.ElementExtensions.Add(new XElement("customImageElement", new XAttribute("type", "image/jpg"), new XAttribute("url", "www.myuri.com/pic1234.jpg")).CreateReader());
This would output:
<customImageElement type="image/jpg" url="www.myprovider.com/pic1234.jpg"></customImageElement>
When I'm done, I add the contentItem to a List<SyndicationItem>
, and add this list when I create the feed (items).
I could also add custom elements to the feed itself, under the <channel>
element:
First add the feed with a list of items:
var feed = new SyndicationFeed("title text", "description text", new Uri("http://myuri.com"), items);
Then add the custom elements to the feed. under the element:
feed.ElementExtensions.Add(new XElement("image",
new XElement("url", null, "http://www.myuri.com/logo.jpg"),
new XElement("title", null, "MyImage"),
new XElement("link", null, "http://myuri.com/contentid=1234"),
new XElement("width", null, "100"),
new XElement("height", null, "100"),
new XElement("description", null, "This is my image")).CreateReader());
This would output:
<rss version="2.0">
<channel>
<title>title text</title>
<link>http://myuri.com</link>
<description>description text</description>
<image>
<url>http://www.myprovider.com/logo.jpg</url>
<title>MyImage</title>
<link>http://myprovider.com/contentid=1234</link>
<width>100</width>
<height>100</height>
<description>This is my image</description>
</image>
<item>
Items added to the items collection
...
...
...
</item>
</channel>
</rss>
That's what I could come up with. If there is a better way, please share.