2using System.Collections.Generic;
13 private Dictionary<string, HtmlAttribute> attributesByName =
null;
14 private LinkedList<HtmlAttribute> attributes =
null;
15 private LinkedList<HtmlNode> children =
null;
16 private readonly
string name;
17 private string @
namespace;
30 this.@
namespace = null;
36 public string Name => this.name;
45 if (this.children is
null)
46 this.children =
new LinkedList<HtmlNode>();
48 this.children.AddLast(Node);
53 if (Attribute.
Name ==
"xmlns")
55 if (
string.IsNullOrEmpty(this.@
namespace))
56 this.@
namespace = Attribute.Value;
60 if (this.attributes is
null)
62 this.attributes =
new LinkedList<HtmlAttribute>();
63 this.attributesByName =
new Dictionary<string, HtmlAttribute>(StringComparer.OrdinalIgnoreCase);
66 if (!this.attributesByName.ContainsKey(Attribute.
Name))
68 this.attributes.AddLast(Attribute);
69 this.attributesByName[Attribute.
Name] = Attribute;
87 public IEnumerable<HtmlNode>
Children => this.children;
92 public IEnumerable<HtmlAttribute>
Attributes => this.attributes;
102 if (this.attributesByName is
null)
108 return this.attributesByName.TryGetValue(
Name, out Attribute);
121 if (!(this.children is
null))
123 foreach (
HtmlNode N
in this.children)
132 if (Start.HasValue && End.HasValue)
133 return this.Document.
HtmlText.Substring(Start.Value, End.Value - Start.Value + 1);
146 StringBuilder sb =
new StringBuilder();
148 if (!(this.children is
null))
150 foreach (
HtmlNode N
in this.children)
153 sb.Append(Text.InlineText);
155 sb.Append(Element.InnerText);
157 sb.Append(Entity.ToString());
163 return sb.ToString();
174 if (!(this.children is
null))
176 foreach (
HtmlNode N
in this.children)
191 if (!(this.children is
null))
193 foreach (
HtmlNode N
in this.children)
194 return N.StartPosition - 1;
211 public override void Export(XmlWriter Output)
213 if (this.@
namespace is
null)
214 Output.WriteStartElement(this.name);
216 Output.WriteStartElement(this.name, this.@
namespace);
218 if (!(this.attributes is
null))
224 if (!(this.children is
null))
226 foreach (
HtmlNode Child
in this.children)
230 Output.WriteEndElement();
237 public override void Export(StringBuilder Output)
240 Output.Append(this.name);
242 if (!(this.attributes is
null))
248 if (!(this.@
namespace is
null))
250 Output.Append(
" xmlns=\"");
251 Output.Append(Xml.XML.Encode(
this.@
namespace));
255 if (this.children is
null)
261 foreach (
HtmlNode Child
in this.children)
265 Output.Append(this.name);
283 return !(this.@
namespace is null);
285 if (this.attributes is
null)
290 if (
string.Compare(Attr.
Name, Name,
true) == 0)
305 return this.@
namespace;
307 if (this.attributes is
null)
312 if (
string.Compare(Attr.
Name,
Name,
true) == 0)
string Content
CDATA Content
string Name
Attribute name.
override void Export(XmlWriter Output)
Exports the HTML document to XML.
string Value
Attribute value.
string HtmlText
HTML text.
Base class for all HTML elements.
bool HasChildren
If the element has children.
virtual bool IsEmptyElement
If the element is an empty element.
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
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 Namespace
Namespace, if provided, null if not.
IEnumerable< HtmlNode > Children
Child nodes, or null if none.
string StartTag
Start tag.
string InnerHtml
Inner HTML
override void Export(XmlWriter Output)
Exports the HTML document to XML.
override string ToString()
Base class for all HTML nodes.
int StartPosition
Start position of element.
HtmlDocument Document
HTML Document
HtmlNode Parent
Parent node, if available.
abstract void Export(XmlWriter Output)
Exports the HTML document to XML.
int EndPosition
End position of element.
string OuterHtml
Outer HTML