如何在C#WindowsPhone中读取元素xml的属性?

How to read the attribute of an element xml in C# Windows Phone?

我正在开发一个可以阅读 rss 的应用程序,我设置了一个 class 这样的

public class Item
{
    [XmlElement("title")]
    public string title { get; set; }
    [XmlElement("description")]
    public string description { get; set; }
    [XmlElement("enclosure")]
    public string enclosure { get; set; }
    [XmlElement("pubDate")]
    public string pubDate { get; set; }
    [XmlElement("link")]
    public string link { get; set; }
}

然而,项目 return 是

<item>
<title>
Colombia 2-1 Paraguay: James Rodriguez and Carlos Bacca score as Jose Pekerman's side reach Copa America quarter-finals
</title>
<link>
http://www.dailymail.co.uk/sport/football/article-3630657/Colombia-2-1-Paraguay-James-Rodriguez-Carlos-Bacca-score-Jose-Pekerman-s-reach-Copa-America-quarter-finals.html?ITO=1490&ns_mchannel=rss&ns_campaign=1490
</link>
<description>
James Rodriguez scored a goal and set up another as Colombia became the first team to clinch a place in the Copa America quarter-finals. The Real Madrid provided the assist for Carlos Bacca's opener.
</description>
<enclosure url="http://i.dailymail.co.uk/i/pix/2016/06/08/05/350A4D8200000578-0-image-a-63_1465360921756.jpg" type="image/jpeg" length="84507" />
<pubDate>Wed, 08 Jun 2016 06:32:45 +0100</pubDate>
<guid>
http://www.dailymail.co.uk/sport/football/article-3630657/Colombia-2-1-Paraguay-James-Rodriguez-Carlos-Bacca-score-Jose-Pekerman-s-reach-Copa-America-quarter-finals.html?ITO=1490&ns_mchannel=rss&ns_campaign=1490
</guid>
</item>

所以,很明显"enclosure"元素return是空字符串,那么如何通过给注解来读取这个"enclosure"标签的"url"属性以上class,请帮帮我!

您必须为附件

单独编写 class
     public class Item
        {
            [XmlElement("title")]
            public string title { get; set; }
            [XmlElement("description")]
            public string description { get; set; }
            [XmlElement("enclosure")]
            public Enclosure enclosure { get; set; }
            [XmlElement("pubDate")]
            public string pubDate { get; set; }
            [XmlElement("link")]
            public string link { get; set; }
        }

    public class Enclosure 
    {
        [XmlAttribute("url")]
        public string Url { get; set; }
    //if enclosure has any child elements it comes under XmlElement like this
    // [XmlElement("enclosurechildelement")]
    // public string enclosurechildelement { get; set; }


    }