如何将 SyndicateElementExtension 添加到 SyndicateItem

发布于 2024-07-25 20:50:44 字数 465 浏览 2 评论 0原文

使用 .NET System.ServiceModel.Syndicate 类...

我想向 SyndicateItem 添加一个新的 SyndicateElementExtension,它将导出以下 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", ?

如何创建具有一些属性的简单 SyndicateElementExtension?

Using the .NET System.ServiceModel.Syndication classes...

I would like to add a new SyndicationElementExtension to a SyndicationItem that will export the following XML:

<media:thumbnail url="http://www.foo.com/keyframe.jpg" width="75" height="50" time="12:05:01.123" />

Something along the lines of:

syndicationItem.ElementExtensions.Add(new SyndicationElementExtension("thumbnail", "http://video.search.yahoo.com/mrss", ?

How do you create a simple SyndicationElementExtension with a few attributes?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

黑色毁心梦 2024-08-01 20:50:44

为了简化下一个试图解决这个问题的人,这里有一个按照文档的内容添加基本项目缩略图(在本例中为 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()
);

您可以如果您想要一个简单的标签,也可以转储属性并在标签名称后设置文本内容,即 http://my.comments/feed

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>.

一腔孤↑勇 2024-08-01 20:50:44

在这里找到答案:http://msdn.microsoft.com/en-us/库/bb943475.aspx


联合元素扩展集合
类也可以用来创建
来自 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());

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());
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文