How To Add A SyndicationElementExtension To A SyndicationItem

房东的猫 提交于 2019-12-05 04:40:22

Just to simplify for the next guy who comes along trying to figure this out, here's a working example of adding a basic item thumbnail (RSS 2.0 enclosure in this case) along the lines of the documentation:

SyndicationItem item = new SyndicationItem();

// populate item...

item.ElementExtensions.Add(
    new XElement( "enclosure",
        new XAttribute( "type", "image/jpeg" ),
        new XAttribute( "url", "http://path.to/my/image.jpg" )
    ).CreateReader()
);

You can also dump the attributes and just set textual content after the tag name if you want a simple tag, i.e. <comments>http://my.comments/feed</comments>.

Found the answer here: http://msdn.microsoft.com/en-us/library/bb943475.aspx

The SyndicationElementExtensionCollection class can also be used to create element extensions from an XmlReader instance. This allows for easy integration with XML processing APIs such as XElement as shown in the following sample code.

feed.ElementExtensions.Add(new XElement("xElementExtension",
        new XElement("Key", new XAttribute("attr1", "someValue"), "Z"),
        new XElement("Value", new XAttribute("attr1", "someValue"), 
        "15")).CreateReader());
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!