[英]How To Add A SyndicationElementExtension To A SyndicationItem
使用.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</comments>
。
在這里找到答案: http : //msdn.microsoft.com/en-us/library/bb943475.aspx
SyndicationElementExtensionCollection類還可用於從XmlReader實例創建元素擴展。 這樣可以輕松地與XML處理API(如XElement)集成,如以下示例代碼所示。
feed.ElementExtensions.Add(new XElement("xElementExtension",
new XElement("Key", new XAttribute("attr1", "someValue"), "Z"),
new XElement("Value", new XAttribute("attr1", "someValue"),
"15")).CreateReader());
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.