Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Stanza.cs
1using System.Xml;
2
4{
8 public class Stanza
9 {
10 private readonly XmlElement rootElement;
11 private XmlElement stanzaElement = null;
12 private readonly string xml;
13 private string content;
14 private readonly int contentStart;
15 private readonly int contentLen;
16
24 public Stanza(XmlElement RootElement, string Xml, int ContentStart, int ContentLen)
25 {
26 this.rootElement = RootElement;
27 this.xml = Xml;
28 this.contentStart = ContentStart;
29 this.contentLen = ContentLen;
30 this.content = null;
31 }
32
39 public Stanza(XmlElement RootElement, XmlElement StanzaElement, string Xml)
40 {
41 this.rootElement = RootElement;
42 this.stanzaElement = StanzaElement;
43 this.xml = Xml;
44 this.content = null;
45 this.contentStart = -1;
46 this.contentLen = 0;
47 }
48
52 public string Content
53 {
54 get
55 {
56 if (this.content is null)
57 {
58 if (this.contentStart < 0)
59 {
60 XmlElement E = this.StanzaElement;
61 if (E is null)
62 this.content = string.Empty;
63 else
64 this.content = E.InnerXml;
65 }
66 else if (this.contentLen <= 0)
67 this.content = string.Empty;
68 else
69 this.content = this.xml.Substring(this.contentStart, this.contentLen);
70 }
71
72 return this.content;
73 }
74 }
75
79 public bool HasContent
80 {
81 get
82 {
83 if (!(this.content is null))
84 return !string.IsNullOrEmpty(this.content);
85
86 if (this.contentStart < 0)
87 {
88 XmlElement E = this.StanzaElement;
89 if (E is null)
90 return false;
91 else
92 {
93 foreach (XmlNode N in E.ChildNodes)
94 {
95 if (N is XmlElement)
96 return true;
97 }
98
99 return false;
100 }
101 }
102 else if (this.contentLen <= 0)
103 return false;
104 else
105 return true;
106 }
107 }
108
112 public XmlElement StanzaElement
113 {
114 get
115 {
116 if (this.stanzaElement is null)
117 {
118 foreach (XmlNode N in this.rootElement.ChildNodes)
119 {
120 if (N is XmlElement E)
121 {
122 this.stanzaElement = E;
123 break;
124 }
125 }
126 }
127
128 return this.stanzaElement;
129 }
130 }
131 }
132}
Contains information about a stanza.
Definition: Stanza.cs:9
Stanza(XmlElement RootElement, XmlElement StanzaElement, string Xml)
Contains information about a stanza.
Definition: Stanza.cs:39
string Content
Literal XML content.
Definition: Stanza.cs:53
XmlElement StanzaElement
Stanza element.
Definition: Stanza.cs:113
bool HasContent
If the stanza has content.
Definition: Stanza.cs:80
Stanza(XmlElement RootElement, string Xml, int ContentStart, int ContentLen)
Contains information about a stanza.
Definition: Stanza.cs:24