Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
HtmlAttribute.cs
2using System.Text;
3using System.Xml;
5
6namespace Waher.Content.Html
7{
11 public class HtmlAttribute : HtmlNode
12 {
13 private ChunkedList<HtmlNode> segments = null;
14 private readonly string fullName;
15 private readonly string localName;
16 private readonly string prefix;
17 private readonly bool hasPrefix;
18 private string @value;
19
30 int EndPosition, string Name, string Value)
32 {
33 SplitName(Name, out this.prefix, out this.localName, out this.hasPrefix);
34 this.fullName = Name;
35 this.@value = Value;
36 this.segments = null;
37 }
38
48 int EndPosition, string Name)
50 {
51 SplitName(Name, out this.prefix, out this.localName, out this.hasPrefix);
52 this.fullName = Name;
53 this.@value = null;
54 this.segments = null;
55 }
56
66 string Name, string Value)
68 {
69 SplitName(Name, out this.prefix, out this.localName, out this.hasPrefix);
70 this.fullName = Name;
71 this.@value = Value;
72 this.segments = null;
73 }
74
84 {
85 SplitName(Name, out this.prefix, out this.localName, out this.hasPrefix);
86 this.fullName = Name;
87 this.@value = null;
88 this.segments = null;
89 }
90
94 public string FullName => this.fullName;
95
99 public string LocalName => this.localName;
100
104 public string Prefix => this.prefix;
105
109 public bool HasPrefix => this.hasPrefix;
110
111 internal void Add(HtmlNode Segment)
112 {
113 if (this.segments is null)
114 this.segments = new ChunkedList<HtmlNode>();
115
116 this.segments.Add(Segment);
117 this.@value = null;
118 }
119
120 internal bool HasSegments => !(this.segments is null);
121
125 public string Value
126 {
127 get
128 {
129 if (this.@value is null)
130 {
131 if (!(this.segments is null))
132 {
133 StringBuilder sb = new StringBuilder();
134
135 foreach (HtmlNode N in this.segments)
136 sb.Append(N.ToString());
137
138 this.@value = sb.ToString();
139 }
140 else
141 this.@value = string.Empty;
142 }
143
144 return this.@value;
145 }
146
147 internal set
148 {
149 this.@value = value;
150 this.segments = null;
151 }
152 }
153
155 public override string ToString()
156 {
157 if (this.hasPrefix)
158 return this.prefix + ":" + this.localName + "=" + this.Value;
159 else
160 return this.localName + "=" + this.Value;
161 }
162
168 public override void Export(XmlWriter Output, Dictionary<string, string> Namespaces)
169 {
170 if (this.hasPrefix)
171 {
172 if (Namespaces.TryGetValue(this.prefix, out string Namespace))
173 Output.WriteAttributeString(this.prefix, this.localName, Namespace, this.@value);
174 }
175 else
176 Output.WriteAttributeString(this.localName, this.@value);
177 }
178
183 public override void Export(StringBuilder Output)
184 {
185 Output.Append(' ');
186 Output.Append(this.fullName);
187 Output.Append("=\"");
188 Output.Append(Xml.XML.Encode(this.@value));
189 Output.Append('"');
190 }
191 }
192}
override void Export(XmlWriter Output, Dictionary< string, string > Namespaces)
Exports the HTML document to XML.
string Prefix
Attribute prefix.
HtmlAttribute(HtmlDocument Document, HtmlElement Parent, int StartPosition, int EndPosition, string Name, string Value)
HTML attribute
bool HasPrefix
If the attribute has a prefix.
HtmlAttribute(HtmlDocument Document, HtmlElement Parent, int StartPosition, string Name)
HTML attribute
string LocalName
Attribute local name.
string FullName
Attribute full name (including prefix).
HtmlAttribute(HtmlDocument Document, HtmlElement Parent, int StartPosition, string Name, string Value)
HTML attribute
string Value
Attribute value.
override void Export(StringBuilder Output)
Exports the HTML document to XML.
HtmlAttribute(HtmlDocument Document, HtmlElement Parent, int StartPosition, int EndPosition, string Name)
HTML attribute
Base class for all HTML elements.
Definition: HtmlElement.cs:13
Base class for all HTML nodes.
Definition: HtmlNode.cs:11
int StartPosition
Start position of element.
Definition: HtmlNode.cs:60
static void SplitName(string FullName, out string Prefix, out string LocalName, out bool HasPrefix)
Splits a full name into a prefix (if available) and a local name.
Definition: HtmlNode.cs:92
HtmlDocument Document
HTML Document
Definition: HtmlNode.cs:49
HtmlNode Parent
Parent node, if available.
Definition: HtmlNode.cs:54
int EndPosition
End position of element.
Definition: HtmlNode.cs:69
A chunked list is a linked list of chunks of objects of type T .
Definition: ChunkedList.cs:54
void Add(T Item)
Adds an item to the collection.
Definition: ChunkedList.cs:272