From cca09f25129664758df85e609208388e53e4ccda Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Mon, 4 Feb 2019 00:01:55 +0000 Subject: Finished parser (used past project) --- Aggregator/Parser/Parser.cs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'Aggregator/Parser') diff --git a/Aggregator/Parser/Parser.cs b/Aggregator/Parser/Parser.cs index 4952a3d..c9ad038 100644 --- a/Aggregator/Parser/Parser.cs +++ b/Aggregator/Parser/Parser.cs @@ -1,10 +1,26 @@ using System; +using System.Linq; +using System.Xml.Linq; using System.Collections.Generic; using Aggregator.Classes; namespace Aggregator.Parser { public static class Parser { - public static IEnumerable
Parse(string xml); - public static IEnumerable> ParseMultiple(string xmls); + public static IEnumerable
Parse(string xml, Config config) { + return XDocument.Parse(xml).Descendants("item") + .Select(articles => articles.Descendants().ToArray()) + .Select(article => new Article() + { + Source = config.Source, + Title = article[config.Title].Value, + Description = article[config.Description].Value, + ArticleLink = article[config.ArticleLink].Value, + ImageLink = article[config.ImageLink].Attribute("url").Value, + PublishDate = DateTime.Parse(article[config.PublishDate].Value) + }).Distinct().ToArray(); + } + public static IEnumerable> ParseMultiple(string xmls) { + + } } } \ No newline at end of file -- cgit v1.2.3-13-gbd6f