Table of Contents

Class HtmlNode

Namespace
SimpleSign.HtmlToPdf.Parsing
Assembly
SimpleSign.HtmlToPdf.dll

Lightweight HTML DOM node. Represents either an element (div, p, table...) or a text node. This is not a full DOM -- just enough structure for layout and rendering.

public sealed class HtmlNode
Inheritance
HtmlNode
Inherited Members

Properties

Attributes

HTML attributes (lowercase keys). Empty for text nodes.

public Dictionary<string, string> Attributes { get; init; }

Property Value

Dictionary<string, string>

Children

Child nodes.

public List<HtmlNode> Children { get; }

Property Value

List<HtmlNode>

ComputedStyle

Computed style after cascade resolution. Populated by StyleResolver.

public ComputedStyle? ComputedStyle { get; set; }

Property Value

ComputedStyle

InlineStyle

Inline style attribute parsed into individual properties. Populated by StyleResolver.

public Dictionary<string, string> InlineStyle { get; set; }

Property Value

Dictionary<string, string>

IsBlock

Gets a value indicating whether this is a block-level element.

public bool IsBlock { get; }

Property Value

bool

IsTableElement

Gets a value indicating whether this is a table-related element.

public bool IsTableElement { get; }

Property Value

bool

IsVoid

Gets a value indicating whether this is a void/self-closing element.

public bool IsVoid { get; }

Property Value

bool

NodeType

Gets the type of this node.

public HtmlNodeType NodeType { get; init; }

Property Value

HtmlNodeType

Parent

Parent node. Null for the root node.

public HtmlNode? Parent { get; }

Property Value

HtmlNode

Tag

Tag name in lowercase (e.g., "div", "p", "table"). Null for text nodes.

public string? Tag { get; init; }

Property Value

string

Text

Text content. Only set for text nodes.

public string? Text { get; init; }

Property Value

string

Methods

AppendChild(HtmlNode)

Adds a child node and sets its parent.

public void AppendChild(HtmlNode child)

Parameters

child HtmlNode

The child node to add.

CreateElement(string, HtmlNode?)

Creates a new element node with the given tag.

public static HtmlNode CreateElement(string tag, HtmlNode? parent = null)

Parameters

tag string

The HTML tag name (will be lowercased).

parent HtmlNode

Optional parent node.

Returns

HtmlNode

A new element node.

CreateText(string, HtmlNode?)

Creates a new text node with the given content.

public static HtmlNode CreateText(string text, HtmlNode? parent = null)

Parameters

text string

The text content.

parent HtmlNode

Optional parent node.

Returns

HtmlNode

A new text node.

Descendants(string)

Gets all descendant elements matching a tag name.

public IEnumerable<HtmlNode> Descendants(string tag)

Parameters

tag string

The tag name to search for (lowercase).

Returns

IEnumerable<HtmlNode>

An enumerable of matching descendant nodes.

GetAttribute(string)

Gets attribute value or null.

public string? GetAttribute(string name)

Parameters

name string

The attribute name (case-insensitive).

Returns

string

The attribute value, or null if not found.

ToString()

Returns a string that represents the current object.

public override string ToString()

Returns

string

A string that represents the current object.