在C#中访问我在RSS中定义的标签

时间:2012-10-11 21:16:35

标签: c# .net rss

我能够将自己的标记添加到RSS源(通过阅读this question中的答案),但现在我似乎无法在代码中访问该标记。

我尝试修改现有的示例Feed(this one),只添加一个标记,如下所示。

<?xml version="1.0"?>
<rss version="2.0" xmlns:my="http://tempuri.org">
   <channel>
      <title>Liftoff News</title>
      <link>http://liftoff.msfc.nasa.gov/</link>
      <description>Liftoff to Space Exploration.</description>      
      <item>
         <title>Star City</title>
         <link>http://liftoff.msfc.nasa.gov/news/2003/news-starcity.asp</link>
         <description>How do Americans get ready to work with Russians aboard the International Space Station? They take a crash course in culture, language and protocol at Russia's &lt;a href="http://howe.iki.rssi.ru/GCTC/gctc_e.htm"&gt;Star City&lt;/a&gt;.</description>
         <pubDate>Tue, 03 Jun 2003 09:39:21 GMT</pubDate>
         <guid>http://liftoff.msfc.nasa.gov/2003/06/03.html#item573</guid>
         <my:br_id>1507</my:br_id>
      </item>          
   </channel>
</rss>

在代码中我有这个类:

public class SimpleSyndicationItem
{
    public DateTimeOffset Date { get; set; }
    public string Title { get; set; }
    public Uri Link { get; set; }
    public string Id{ get; set; }

    public SimpleSyndicationItem(DateTimeOffset date, string title, Uri link, string id)
    {
        Date = date;
        Title = title;
        Link = link;
        Id = id;
    }
}

Id属性应该在my:br_id中接收值,现在,在阅读过程中我有这个:

var RssItems = new ObservableCollection<SimpleSyndicationItem>();
var reader = XmlReader.Create("rssexample.xml");    
var feed = SyndicationFeed.Load(reader);

foreach(var item in feed.Items)
{
  //This is the part where I want to access the tag's value, notice the ??
  RssItems.Add(new SimpleSyndicationItem(item.PublishDate, item.Title.text,
                                         item.Links[0].Uri, item.??));
}

至少intellisense没有显示br_id,所以我想知道在代码中访问此标记的正确方法是什么。

1 个答案:

答案 0 :(得分:1)

item.ElementExtensions[0]怎么样?