代码之家  ›  专栏  ›  技术社区  ›  Shawn Miller

如何将联合扩展添加到联合项

  •  8
  • Shawn Miller  · 技术社区  · 15 年前

    正在使用.NET System.ServiceModel.Syndication类…

    我想将新的SyndicationElementExtension添加到将导出以下XML的SyndicationItem中:

    <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", ?
    

    如何创建具有几个属性的简单联合扩展?

    2 回复  |  直到 8 年前
        1
  •  11
  •   nickb    13 年前

    为了简化下一个试图解决这个问题的人,这里有一个添加基本项目缩略图的工作示例( 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> .

        2
  •  10
  •   Shawn Miller    15 年前

    在这里找到了答案: http://msdn.microsoft.com/en-us/library/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());
    
    推荐文章