Receiving items from a feed - Xamarin

0

With this method I search all the items in a url. Now I need to select only the item from the fifth position, how can I do this and what changes should I make?

private async Task<List<FeedItem>> ParseFeed(string rss)
    {
        return await Task.Run(() =>
        {
            var xdoc = XDocument.Parse(rss);
            var id = 0;
            return (from item in xdoc.Descendants("item")
                    let enclosure = item.Element("enclosure")
                    where enclosure != null
                    select new FeedItem
                    {
                        Title = (string)item.Element("title"),
                        Description = (string)item.Element("description"),
                        Link = (string)item.Element("link"),
                        PublishDate = DateTime.Parse((string)item.Element("pubDate")).ToUniversalTime().ToString("dd/MM/yyyy HH:mm:ss"),
                        Category = (string)item.Element("category"),
                        Mp3Url = (string)enclosure.Attribute("url"),
                        Image = (string)enclosure.Attribute("url"),
                        Color_category =Convert.ToString(int.Parse((string)item.Element("color")), 16).PadLeft(6, '0'),
                    Id = id++
                    }).ToList();
        });
    }
    
asked by anonymous 06.06.2017 / 16:33

1 answer

0

Two things to note here:

  • Your method is async ) so for best result, you should expect the result from an operator called await .
  • Your method returns a list of FeedItem so we should just store this return and fetch the position by the index from the list.

    // Armazena o feed em uma lista List<FeedItem> myFeedList = await ParseFeed("endereço do feed"); // Busca o quinto elemento da lista, neste caso representado pelo número 5 (coloque a posição que desejar) FeedItem feedItem = myFeedList[5];

  • 07.06.2017 / 13:57