FeedReader.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. namespace FormulaOneApp.Rss
  2. {
  3. using System;
  4. using System.Xml.Linq;
  5. using Exceptions;
  6. using Models;
  7. using Readers;
  8. public static class FeedReader
  9. {
  10. /// <summary>
  11. /// Parse the xml string into a RssFeed object
  12. /// </summary>
  13. /// <param name="xml"></param>
  14. /// <returns></returns>
  15. public static RssFeed LoadFeed(string xml)
  16. {
  17. XDocument doc;
  18. try
  19. {
  20. doc = XDocument.Parse(xml);
  21. }
  22. catch (Exception ex)
  23. {
  24. throw new NotSupportedFeedException("Not Supported", ex);
  25. }
  26. RssType type = BaseReader.GetFeedType(doc);
  27. BaseReader reader;
  28. switch (type)
  29. {
  30. case RssType.Atom:
  31. reader = new AtomReader();
  32. break;
  33. case RssType.Rdf:
  34. reader = new RDFReader();
  35. break;
  36. default:
  37. reader = new Reader();
  38. break;
  39. }
  40. return reader.LoadFeed(doc);
  41. }
  42. }
  43. }