예제 #1
0
        /// <summary>
        /// RSS all versions
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        private static RssSchema ParseItem(XElement item)
        {
            var rssItem = new RssSchema();

            rssItem.Title   = item.GetSafeElementString("title").Trim();
            rssItem.FeedUrl = item.GetSafeElementString("link");

            string description = item.GetSafeElementString("description");

            if (string.IsNullOrEmpty(description))
            {
                description = item.GetSafeElementString("content");
            }

            rssItem.Summary = Utility.DecodeHtml(description).Trim().Truncate(500, true);
            rssItem.Summary = RssHelper.SanitizeString(rssItem.Summary);
            rssItem.Content = RssHelper.SanitizeString(description);

            string id = item.GetSafeElementString("guid").Trim();

            if (string.IsNullOrEmpty(id))
            {
                id = item.GetSafeElementString("id").Trim();
                if (string.IsNullOrEmpty(id))
                {
                    id = rssItem.FeedUrl;
                }
            }
            rssItem.Id = id;

            return(rssItem);
        }
예제 #2
0
        /// <summary>
        /// Atom reader implementation to parse Atom content.
        /// </summary>
        /// <param name="doc"></param>
        /// <returns></returns>
        public override ObservableCollection <RssSchema> LoadFeed(XDocument doc)
        {
            try
            {
                var feed = new ObservableCollection <RssSchema>();

                if (doc.Root == null)
                {
                    return(feed);
                }

                var items = doc.Root.Elements(doc.Root.GetDefaultNamespace() + "entry").Select(item => new RssSchema
                {
                    Title       = item.GetSafeElementString("title").Trim(),
                    Summary     = RssHelper.SanitizeString(Utility.DecodeHtml(GetItemSummary(item)).Trim().Truncate(500, true)),
                    Content     = GetItemSummary(item),
                    ImageUrl    = GetItemImage(item),
                    PublishDate = item.GetSafeElementDate("published"),
                    FeedUrl     = item.GetLink("alternate"),
                }).ToList <RssSchema>();

                feed = new ObservableCollection <RssSchema>(items);

                return(feed);
            }
            catch (Exception ex)
            {
                AppLogs.WriteError("AtomReader.LoadFeed", ex.Message);
                return(null);
            }
        }
예제 #3
0
        private static RssSchema GetRssSchema(XElement item)
        {
            RssSchema rssItem = new RssSchema
            {
                Author      = GetItemAuthor(item),
                Title       = Utility.DecodeHtml(item.GetSafeElementString("title").Trim()),
                Summary     = RssHelper.SanitizeString(Utility.DecodeHtml(GetItemSummary(item)).Trim().Truncate(500, true)),
                Content     = GetItemSummary(item),
                ImageUrl    = GetItemImage(item),
                PublishDate = item.GetSafeElementDate("published"),
                FeedUrl     = item.GetLink("alternate"),
            };

            string id = item.GetSafeElementString("guid").Trim();

            if (string.IsNullOrEmpty(id))
            {
                id = item.GetSafeElementString("id").Trim();
                if (string.IsNullOrEmpty(id))
                {
                    id = rssItem.FeedUrl;
                }
            }
            rssItem.Id = id;
            return(rssItem);
        }
예제 #4
0
        /// <summary>
        /// RSS all versions
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        private static RssSchema ParseItem(XElement item)
        {
            var rssItem = new RssSchema();

            rssItem.Title   = item.GetSafeElementString("title").Trim();
            rssItem.FeedUrl = item.GetSafeElementString("link");

            string content = item.GetSafeElementString("encoded", "http://purl.org/rss/1.0/modules/content/");

            if (string.IsNullOrEmpty(content))
            {
                content = item.GetSafeElementString("content");
            }


            string description = item.GetSafeElementString("content");

            rssItem.Content = string.IsNullOrEmpty(content) ? RssHelper.SanitizeString(description) : RssHelper.SanitizeString(content);

            rssItem.Summary = Utility.DecodeHtml(description).Trim().Truncate(500, true);

            rssItem.Summary = RssHelper.SanitizeString(rssItem.Summary);


            return(rssItem);
        }