2016-06-08 1 views
0

, 그C# Windows Phone에서 요소 xml의 특성을 읽는 방법? 나는 RSS를 읽을 수있는 응용 프로그램을 개발

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; } 
} 

Howerver 같은 클래스, 항목이

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

그래서, 그것은 "인클로저"요소가 비어 반환 것이 분명 것을 돌려 설정 문자열, 위의 클래스와 같은 주석을 제공하여이 "인클로저"태그의 "url"속성을 읽는 방법, 도와주세요!

답변

0

당신은 인클로저에 대한 별도의 클래스를 작성해야

 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; } 


    } 
관련 문제