14 private Dictionary<string, HtmlAttribute> attributesByName =
null;
16 private Dictionary<string, HtmlAttribute> namespacesByPrefix =
null;
18 private readonly
string fullName;
19 private readonly
string localName;
20 private readonly
string prefix;
21 private readonly
bool hasPrefix;
22 private string @
namespace;
34 SplitName(Name, out this.prefix, out this.localName, out this.hasPrefix);
36 this.@
namespace = null;
66 if (this.children is
null)
69 this.children.
Add(Node);
76 if (
string.IsNullOrEmpty(this.@
namespace))
77 this.@
namespace = Attribute.Value;
81 if (this.namespacesByPrefix is
null)
82 this.namespacesByPrefix =
new Dictionary<string, HtmlAttribute>();
84 this.namespacesByPrefix[Attribute.
LocalName] = Attribute;
88 if (this.attributes is
null)
91 this.attributesByName =
new Dictionary<string, HtmlAttribute>(StringComparer.OrdinalIgnoreCase);
94 if (!this.attributesByName.ContainsKey(Attribute.
FullName))
96 this.attributes.
Add(Attribute);
97 this.attributesByName[Attribute.
FullName] = Attribute;
115 public IEnumerable<HtmlNode>
Children => this.children;
120 public IEnumerable<HtmlAttribute>
Attributes => this.attributes;
130 if (this.attributesByName is
null)
136 return this.attributesByName.TryGetValue(Name, out Attribute);
149 if (!(this.children is
null))
151 foreach (
HtmlNode N
in this.children)
160 if (Start.HasValue && End.HasValue)
161 return this.Document.
HtmlText.Substring(Start.Value, End.Value - Start.Value + 1);
174 StringBuilder sb =
new StringBuilder();
176 if (!(this.children is
null))
178 foreach (
HtmlNode N
in this.children)
181 sb.Append(Text.InlineText);
183 sb.Append(Element.InnerText);
185 sb.Append(Entity.ToString());
191 return sb.ToString();
202 if (!(this.children is
null))
204 foreach (
HtmlNode N
in this.children)
219 if (!(this.children is
null))
221 foreach (
HtmlNode N
in this.children)
222 return N.StartPosition - 1;
240 public override void Export(XmlWriter Output, Dictionary<string, string> Namespaces)
244 if (!(this.namespacesByPrefix is
null))
246 foreach (KeyValuePair<string, HtmlAttribute> P
in this.namespacesByPrefix)
248 if (Namespaces.TryGetValue(P.Key, out
string s))
250 if (NamespaceBak is
null)
253 NamespaceBak.
Add(
new KeyValuePair<string, string>(P.Key, s));
256 Namespaces[P.Key] = P.Value.Value;
262 if (Namespaces.TryGetValue(
this.prefix, out
string s))
263 Output.WriteStartElement(
this.prefix,
this.localName, s);
265 Output.WriteStartElement(this.prefix, this.localName, this.@
namespace);
267 else if (this.@
namespace is
null)
268 Output.WriteStartElement(this.localName);
270 Output.WriteStartElement(this.localName, this.@
namespace);
272 if (!(this.attributes is
null))
275 Attr.
Export(Output, Namespaces);
278 if (!(this.namespacesByPrefix is
null))
280 foreach (KeyValuePair<string, HtmlAttribute> P
in this.namespacesByPrefix)
281 P.Value.Export(Output, Namespaces);
284 if (!(this.children is
null))
286 foreach (
HtmlNode Child
in this.children)
287 Child.
Export(Output, Namespaces);
290 Output.WriteEndElement();
292 if (!(this.namespacesByPrefix is
null))
294 foreach (KeyValuePair<string, HtmlAttribute> P
in this.namespacesByPrefix)
295 Namespaces.Remove(P.Key);
298 if (!(NamespaceBak is
null))
300 foreach (KeyValuePair<string, string> P
in NamespaceBak)
301 Namespaces[P.Key] = P.Value;
309 public override void Export(StringBuilder Output)
312 Output.Append(this.fullName);
314 if (!(this.attributes is
null))
320 if (!(this.@
namespace is
null))
322 Output.Append(
" xmlns=\"");
323 Output.Append(Xml.XML.Encode(
this.@
namespace));
327 if (!(this.namespacesByPrefix is
null))
329 foreach (KeyValuePair<string, HtmlAttribute> P
in this.namespacesByPrefix)
330 P.Value.Export(Output);
333 if (this.children is
null)
339 foreach (
HtmlNode Child
in this.children)
343 Output.Append(this.fullName);
360 if (Name.StartsWith(
"xmlns"))
363 return !(this.@
namespace is null);
365 if (Name.Length > 6 && Name[5] ==
':')
367 if (this.namespacesByPrefix is
null)
370 return this.namespacesByPrefix.ContainsKey(Name.Substring(6));
374 if (this.attributes is
null)
379 if (
string.Compare(Attr.
FullName, Name,
true) == 0)
393 if (Name.StartsWith(
"xmlns"))
396 return this.@
namespace;
398 if (Name.Length > 6 && Name[5] ==
':')
400 if (this.namespacesByPrefix is
null)
403 if (this.namespacesByPrefix.TryGetValue(Name.Substring(6), out
HtmlAttribute NsAttr))
410 if (this.attributesByName is
null)
413 if (this.attributesByName.TryGetValue(Name, out
HtmlAttribute Attr))
string Content
CDATA Content
override void Export(XmlWriter Output, Dictionary< string, string > Namespaces)
Exports the HTML document to XML.
string Prefix
Attribute prefix.
bool HasPrefix
If the attribute has a prefix.
string LocalName
Attribute local name.
string FullName
Attribute full name (including prefix).
string HtmlText
HTML text.
Base class for all HTML elements.
bool HasPrefix
If the element has a prefix.
bool HasChildren
If the element has children.
virtual bool IsEmptyElement
If the element is an empty element.
override void Export(XmlWriter Output, Dictionary< string, string > Namespaces)
Exports the HTML document to XML.
HtmlElement(HtmlDocument Document, HtmlElement Parent, int StartPosition, string Name)
Base class for all HTML elements.
bool TryGetAttribute(string Name, out HtmlAttribute Attribute)
Tries to get an attribute from the element, by its name.
string InnerText
Inner Text
string Prefix
Element prefix.
bool HasAttribute(string Name)
If the element has an attribute with a given (case-insensitive) name.
IEnumerable< HtmlAttribute > Attributes
Attributes, or null if none.
string GetAttribute(string Name)
Gets a given attribute value, if available. The empty string is returned if the attribute does not ex...
override void Export(StringBuilder Output)
Exports the HTML document to XML.
int EndPositionOfStartTag
End position of start tag.
bool HasAttributes
If the element has attributes.
string FullName
Element full name (including prefix).
string Namespace
Namespace, if provided, null if not.
string LocalName
Element local name.
IEnumerable< HtmlNode > Children
Child nodes, or null if none.
string StartTag
Start tag.
string InnerHtml
Inner HTML
override string ToString()
Base class for all HTML nodes.
int StartPosition
Start position of element.
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.
HtmlDocument Document
HTML Document
HtmlNode Parent
Parent node, if available.
int EndPosition
End position of element.
abstract void Export(XmlWriter Output, Dictionary< string, string > Namespaces)
Exports the HTML document to XML.
string OuterHtml
Outer HTML
A chunked list is a linked list of chunks of objects of type T .
void Add(T Item)
Adds an item to the collection.