使用.NET System.ServiceModel.Syndication类…
我想向SyndicationItem添加一个新的SyndicationElementExtension,它将导出以下XML:
<media:thumbnail url="http://www.foo.com/keyframe.jpg" width="75" height="50" time="12:05:01.123" />
有点像:
syndicationItem.ElementExtensions.Add(new SyndicationElementExtension("thumbnail","http://video.search.yahoo.com/mRSS",?
如何使用一些属性创建简单的SyndicationElementExtension?
解决方法
为了简化下一个试图解决这个问题的人,下面是一个在文档中添加基本项缩略图(在这种情况下为RSS 2.0附件)的工作示例:
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() );
如果你想要一个简单的标签,你也可以转储属性,只在标签名后面设置文字内容,即< comments> http://my.comments/Feed\u0026lt; / comments>.