Esempio n. 1
0
        /// <summary>
        /// Retieves strong type for passed item.
        /// </summary>
        /// <param name="item">XElement to parse.</param>
        /// <returns>Strong typed object.</returns>
        private static RssSchema GetRssSchema(XElement item)
        {
            RssSchema rssItem = new RssSchema
            {
                Author      = GetItemAuthor(item),
                Title       = item.GetSafeElementString("title").Trim().DecodeHtml(),
                ImageUrl    = GetItemImage(item),
                PublishDate = item.GetSafeElementDate("published"),
                FeedUrl     = item.GetLink("alternate"),
            };

            var content = GetItemContent(item);

            // Removes scripts from html
            if (!string.IsNullOrEmpty(content))
            {
                rssItem.Summary = ProcessHtmlSummary(content);
                rssItem.Content = ProcessHtmlContent(content);
            }

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

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

            rssItem.InternalID = id;
            return(rssItem);
        }
        /// <summary>
        /// Parses XElement item into strong typed object.
        /// </summary>
        /// <param name="item">XElement item to parse.</param>
        /// <returns>Strong typed object.</returns>
        private static RssSchema ParseItem(XElement item)
        {
            var rssItem = new RssSchema();

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

            rssItem.Author = GetItemAuthor(item);

            string content = item.GetSafeElementString("encoded", NsRdfContentNamespaceUri);

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

            var summary = item.GetSafeElementString("description");

            if (string.IsNullOrEmpty(summary))
            {
                summary = item.GetSafeElementString("encoded", NsRdfContentNamespaceUri);
            }

            // Removes scripts from html
            if (!string.IsNullOrEmpty(summary))
            {
                rssItem.Summary = ProcessHtmlSummary(summary);
            }

            if (!string.IsNullOrEmpty(content))
            {
                rssItem.Content = ProcessHtmlContent(content);
            }

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

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

            rssItem.InternalID = id;

            return(rssItem);
        }