diff options
author | Aryadev Chavali <aryadevchavali1@gmail.com> | 2019-02-04 00:14:19 +0000 |
---|---|---|
committer | Aryadev Chavali <aryadevchavali1@gmail.com> | 2019-02-04 00:14:19 +0000 |
commit | 4dac7b86f724d962e7d58606f03bc96d5cd9d0c2 (patch) | |
tree | 2b586ba6cdf9d86c046aab8237c6fa9b87d9f4ec /Aggregator | |
parent | 3ff6850bfdadb9f13f5b05f8f2153e6bfe978da9 (diff) | |
download | newsaggregator-4dac7b86f724d962e7d58606f03bc96d5cd9d0c2.tar.gz newsaggregator-4dac7b86f724d962e7d58606f03bc96d5cd9d0c2.tar.bz2 newsaggregator-4dac7b86f724d962e7d58606f03bc96d5cd9d0c2.zip |
Added comments
Diffstat (limited to 'Aggregator')
-rw-r--r-- | Aggregator/Parser/Parser.cs | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/Aggregator/Parser/Parser.cs b/Aggregator/Parser/Parser.cs index 5a6e7e6..3bd141d 100644 --- a/Aggregator/Parser/Parser.cs +++ b/Aggregator/Parser/Parser.cs @@ -5,11 +5,22 @@ using System.Collections.Generic; using Aggregator.Classes; namespace Aggregator.Parser { + /// <summary> + /// Class to provide Parsing services + /// </summary> public static class Parser { + + /// <summary> + /// Parse a single xml code, given a config, to Articles + /// </summary> + /// <param name="xml">XML code from an RSS feed</param> + /// <param name="config">Config that tells parser where to get relevant information</param> + /// <returns>Parsed articles from XML code</returns> public static IEnumerable<Article> Parse(string xml, Config config) { - return XDocument.Parse(xml).Descendants("item") - .Select(articles => articles.Descendants().ToArray()) - .Select(article => new Article() + + return XDocument.Parse(xml).Descendants("item") //make an XDocument out of the xml + .Select(articles => articles.Descendants().ToArray()) //turn each 'item' into it's respective descendants + .Select(article => new Article() //make a new article from each 'item' article, using config for pointers { Source = config.Source, Title = article[config.Title].Value, @@ -17,14 +28,15 @@ namespace Aggregator.Parser { ArticleLink = article[config.ArticleLink].Value, ImageLink = article[config.ImageLink].Attribute("url").Value, PublishDate = DateTime.Parse(article[config.PublishDate].Value) - }).Distinct(); + }).Distinct(); //remove any duplicates } public static IEnumerable<Article> ParseMultiple(string[] xmls, List<Config> configs) { - if (configs.Count == 0 || xmls.Length == 0 || (xmls.Length != configs.Count)) { - return null; + if (configs.Count == 0 || xmls.Length == 0 || (xmls.Length != configs.Count)) { + return null; //for bad cases } else { - return xmls.Select((xml, index) => Parse(xml, configs[index])).SelectMany(i => i); + return xmls.Select((xml, index) => Parse(xml, configs[index])) //Parse each item + .SelectMany(i => i); //remove distinctions between each set of articles } } } |