Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
RssDocument.cs
1using System;
2using System.Collections.Generic;
3using System.Xml;
6
7namespace Waher.Content.Rss
8{
12 public class RssDocument
13 {
14 private readonly XmlDocument xml;
15
21 public RssDocument(XmlDocument Xml, Uri BaseUri)
22 {
23 if (Xml is null)
24 throw new ArgumentNullException(nameof(Xml));
25
26 if (Xml.DocumentElement is null)
27 throw new ArgumentException("Missing XML.", nameof(Xml));
28
29 if (Xml.DocumentElement.LocalName != "rss")
30 throw new ArgumentException("Not an RSS document.", nameof(Xml));
31
32 this.xml = Xml;
33 this.Version = XML.Attribute(Xml.DocumentElement, "version", 0.0);
34
35 List<RssChannel> Channels = new List<RssChannel>();
36 List<RssWarning> Warnings = new List<RssWarning>();
37 List<IRssExtension> Extensions = new List<IRssExtension>();
38
39 foreach (XmlNode N in Xml.DocumentElement.ChildNodes)
40 {
41 if (!(N is XmlElement E))
42 continue;
43
44 if (E.NamespaceURI == Xml.NamespaceURI)
45 {
46 switch (E.LocalName)
47 {
48 case "channel":
49 RssChannel Channel = new RssChannel(E, BaseUri);
50 Channels.Add(Channel);
51 Warnings.AddRange(Channel.Warnings);
52 break;
53
54 default:
55 Warnings.Add(new RssWarning(E));
56 break;
57 }
58 }
59 else
60 {
61 IRssExtension Extension = Types.FindBest<IRssExtension, XmlElement>(E);
62 if (Extension is null)
63 Warnings.Add(new RssWarning(E));
64 else
65 Extensions.Add(Extension.Create(E, BaseUri));
66 }
67 }
68
69 this.Channels = Channels.ToArray();
70 this.Warnings = Warnings.ToArray();
71 this.Extensions = Extensions.ToArray();
72 }
73
77 public XmlDocument Xml => this.xml;
78
82 public double Version { get; }
83
87 public RssChannel[] Channels { get; }
88
92 public RssWarning[] Warnings { get; }
93
97 public IRssExtension[] Extensions { get; } = null;
98 }
99}
Contains information about an RSS Channel.
Definition: RssChannel.cs:12
RssWarning[] Warnings
Any warning messages created during parsing.
Definition: RssChannel.cs:157
Contains information from an RSS feed.
Definition: RssDocument.cs:13
RssChannel[] Channels
Channels
Definition: RssDocument.cs:87
RssWarning[] Warnings
Any warning messages created during parsing.
Definition: RssDocument.cs:92
IRssExtension[] Extensions
Extensions
Definition: RssDocument.cs:97
double Version
Version of RSS document.
Definition: RssDocument.cs:82
RssDocument(XmlDocument Xml, Uri BaseUri)
Contains information from an RSS feed.
Definition: RssDocument.cs:21
XmlDocument Xml
RSS XML document.
Definition: RssDocument.cs:77
Contains a warning message.
Definition: RssWarning.cs:9
Helps with common XML-related tasks.
Definition: XML.cs:19
static string Attribute(XmlElement E, string Name)
Gets the value of an XML attribute.
Definition: XML.cs:914
Static class that dynamically manages types and interfaces available in the runtime environment.
Definition: Types.cs:14
Interface for RSS extensions
IRssExtension Create(XmlElement Xml, Uri BaseUri)
Creates a new instance of the RSS extension.