Esempio n. 1
0
        public List <NewsItem> GetNews(Feed feed, XmlDocument document)
        {
            var root    = XmlParseUtils.GetRootNode(document);
            var entries = XmlParseUtils.FindChildrenByTagName(root, "entry");

            var newsItems = new List <NewsItem>();

            foreach (var entry in entries)
            {
                var id       = XmlParseUtils.FindFirstChildByTagName(entry, "id").InnerText;
                var title    = XmlParseUtils.FindFirstChildByTagName(entry, "title").InnerText;
                var contents = XmlParseUtils.FindFirstChildByTagName(entry, "summary").InnerText;
                var url      = XmlParseUtils.FindFirstChildByTagName(entry, "link").Attributes.GetNamedItem("href").Value;

                var datetimeElement = XmlParseUtils.FindFirstChildByTagName(entry, "updated");
                var datetime        = datetimeElement != null?DateTime.ParseExact(datetimeElement.InnerText, "yyyy-MM-ddTHH:mm:ssZ", CultureInfo.GetCultureInfo("en-EN")) : (DateTime?)null;

                var newsItem = new NewsItem
                {
                    Guid     = id,
                    Title    = title,
                    Contents = contents,
                    Datetime = datetime,
                    Url      = url,
                    Feed     = feed,
                    Favorite = false,
                    Unread   = true
                };

                newsItems.Add(newsItem);
            }

            return(newsItems);
        }
Esempio n. 2
0
        public string GetName(XmlDocument document)
        {
            var root  = XmlParseUtils.GetRootNode(document);
            var title = XmlParseUtils.FindFirstChildByTagName(root, "title");

            return(title.InnerText);
        }
Esempio n. 3
0
        public List <NewsItem> GetNews(Feed feed, XmlDocument document)
        {
            var root    = XmlParseUtils.GetRootNode(document);
            var channel = XmlParseUtils.FindFirstChildByTagName(root, "channel");
            var items   = XmlParseUtils.FindChildrenByTagName(channel, "item");

            var newsItems = new List <NewsItem>();

            foreach (var item in items)
            {
                var url      = XmlParseUtils.FindFirstChildByTagName(item, "link").InnerText;
                var title    = XmlParseUtils.FindFirstChildByTagName(item, "title").InnerText;
                var contents = XmlParseUtils.FindFirstChildByTagName(item, "description").InnerText;

                // Como la etiqueta <guid> es opcional en la especificación RSS 2.0, utilizamos
                // la URL de la noticia como identificador en caso de que el GUID no venga indicado
                var guidElement = XmlParseUtils.FindFirstChildByTagName(item, "guid");
                var guid        = guidElement != null ? guidElement.InnerText : url;

                var datetimeElement = XmlParseUtils.FindFirstChildByTagName(item, "pubDate");
                var datetime        = datetimeElement != null?ParseDateTimeString(datetimeElement.InnerText) : (DateTime?)null;

                var newsItem = new NewsItem
                {
                    Guid     = guid,
                    Title    = title,
                    Contents = contents,
                    Datetime = datetime,
                    Url      = url,
                    Feed     = feed,
                    Favorite = false,
                    Unread   = true
                };

                newsItems.Add(newsItem);
            }

            return(newsItems);
        }