Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/
Class

HtmlDocument

OfficeIMO.Html.Dom

Namespace
OfficeIMO.Html.Dom
Assembly
OfficeIMO.Html.Core
Source revision
ba882f6b0d07 with working tree changes
Modifiers
sealed

An owned HTML tree with explicit snapshot and mutation semantics. Mutable documents require a single owner.

Inheritance

Usage

Explore 11 API references to this type

This type appears in these public API surfaces even when no hand-authored example is attached directly to the page.

Accepted by parameters 1

Constructors

public HtmlDocument(IHtmlDomServices services, string providerId, HtmlDocumentMode mode = Standards) #

Creates an empty mutable document for a parser or programmatic authoring.

Parameters

services OfficeIMO.Html.Dom.IHtmlDomServices required
providerId string required
mode OfficeIMO.Html.Dom.HtmlDocumentMode = Standards optional

Methods

public HtmlDocument Clone() #

Creates an independent mutable clone, preserving node IDs and source positions.

public HtmlDocument CloneAttached(CancellationToken cancellationToken = default) #

Creates an independent mutable copy of the attached tree, including template contents, without retaining detached editing history. Attached node IDs and original source offsets are preserved.

Parameters

cancellationToken System.Threading.CancellationToken = default optional
Cooperative cancellation while copying nodes and attributes.
public HtmlNode CreateComment(string text) #

Creates a comment in this mutable document.

Parameters

text string required

Returns

HtmlNode
public HtmlDocumentType CreateDocumentType(string name, string publicIdentifier = "", string systemIdentifier = "") #

Creates a document type with the supplied identifiers.

Parameters

name string required
publicIdentifier string = "" optional
systemIdentifier string = "" optional
public HtmlElement CreateElement(string localName, string namespaceUri = "http://www.w3.org/1999/xhtml", string? prefix = null) #

Creates a detached element in this mutable document.

Parameters

localName string required
namespaceUri string = "http://www.w3.org/1999/xhtml" optional
prefix string? = null optional
public HtmlDocumentFragment CreateFragment() #

Creates a detached fragment in this mutable document.

public HtmlNode CreateTextNode(string text) #

Creates decoded text in this mutable document.

Parameters

text string required

Returns

HtmlNode
public HtmlDocument Edit(Action<HtmlDocument> edit) #

Applies edits to an independent clone and freezes the returned snapshot.

Parameters

edit System.Action<OfficeIMO.Html.Dom.HtmlDocument> required
public HtmlDocument Freeze() #

Freezes this instance. Every retained node handle becomes read-only.

public HtmlNode? GetNode(int nodeId) #

Finds a node by its document-local identity, including detached nodes.

Parameters

nodeId int required

Returns

HtmlNode?
public HtmlDocumentFragment GetOrCreateTemplateContent(HtmlElement template) #

Creates or returns this template element's separate content fragment.

Parameters

template OfficeIMO.Html.Dom.HtmlElement required
public HtmlNode ImportNode(HtmlNode source, bool deep = true, CancellationToken cancellationToken = default) #

Copies a node into this mutable document and returns the detached copy. The source remains unchanged. Copies have fresh destination-local IDs and no source offsets; namespaces, attributes, decoded data and, for deep copies, template contents are preserved.

Parameters

source OfficeIMO.Html.Dom.HtmlNode required
An element, text, comment, document type or fragment from any owned document.
deep bool = true optional
Whether to include descendants and template contents.
cancellationToken System.Threading.CancellationToken = default optional
Cooperative cancellation while copying nodes.

Returns

HtmlNode
public void SetSourceIndex(HtmlNode node, int? sourceIndex) #

Attaches an original UTF-16 source position while constructing a mutable tree.

Parameters

node OfficeIMO.Html.Dom.HtmlNode required
sourceIndex int? required

Properties

public Guid SnapshotId { get; } #

Unique identity of this tree instance; clones have independent identities.

public long Revision { get; private set; } #

Mutation revision used to invalidate derived state.

public bool IsReadOnly { get; private set; } #

Whether this tree rejects further mutation, including detached nodes.

public string ProviderId { get; } #

Parser identity attached when the tree was created.

public HtmlDocumentMode Mode { get; } #

Layout compatibility mode established by the parser.

public IHtmlDomServices Services { get; } #

Syntax services used for queries and serialization.

public HtmlElement? DocumentElement { get; } #

Root element, if present.

public HtmlElement? Body { get; } #

Direct HTML body or frameset child of the root.

public HtmlElement? Head { get; } #

Direct HTML head child of the root.