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