aboutsummaryrefslogtreecommitdiff
path: root/Aggregator/Parser
diff options
context:
space:
mode:
authorAryadev Chavali <aryadevchavali1@gmail.com>2019-02-04 00:01:55 +0000
committerAryadev Chavali <aryadevchavali1@gmail.com>2019-02-04 00:01:55 +0000
commitcca09f25129664758df85e609208388e53e4ccda (patch)
treea9491da0f2e81c6a4be767717296bfd784e73f55 /Aggregator/Parser
parentaa550f049592c373db925b68d0604ca18319fcee (diff)
downloadnewsaggregator-cca09f25129664758df85e609208388e53e4ccda.tar.gz
newsaggregator-cca09f25129664758df85e609208388e53e4ccda.tar.bz2
newsaggregator-cca09f25129664758df85e609208388e53e4ccda.zip
Finished parser (used past project)
Diffstat (limited to 'Aggregator/Parser')
-rw-r--r--Aggregator/Parser/Parser.cs20
1 files changed, 18 insertions, 2 deletions
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<Article> Parse(string xml);
- public static IEnumerable<IEnumerable<Article>> ParseMultiple(string xmls);
+ public static IEnumerable<Article> 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<IEnumerable<Article>> ParseMultiple(string xmls) {
+
+ }
}
} \ No newline at end of file