# HtmlDocument

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

Class 

`OfficeIMO.Html.Dom`

**Namespace**

`OfficeIMO.Html.Dom`

**Assembly**

`OfficeIMO.Html.Core`

**Source revision**

`ba882f6b0d07` with working tree changes

**Source**

[HtmlDocument.cs:6](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlDocument.cs#L6)

**Base**

`HtmlNode`

**Modifiers**

sealed

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

## Inheritance

- [HtmlNode](/api/html-core/officeimo-html-dom-htmlnode/)
- HtmlDocument

## 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.

### Returned or exposed by 10

- Method [HtmlDocument.Clone](/api/html-core/officeimo-html-dom-htmldocument/#method-clone)
- Method [HtmlDocument.CloneAttached](/api/html-core/officeimo-html-dom-htmldocument/#method-cloneattached-threading-cancellationtoken)
- Method [HtmlDocument.Edit](/api/html-core/officeimo-html-dom-htmldocument/#method-edit-action-officeimo-html-dom-htmldocument)
- Method [HtmlDocument.Freeze](/api/html-core/officeimo-html-dom-htmldocument/#method-freeze)
- Property [HtmlDocument.Document](/api/html-core/officeimo-html-dom-htmldocument/#property-document)
- Property [HtmlDocumentFragment.Document](/api/html-core/officeimo-html-dom-htmldocumentfragment/#property-document)
- Property [HtmlDocumentType.Document](/api/html-core/officeimo-html-dom-htmldocumenttype/#property-document)
- Property [HtmlElement.Document](/api/html-core/officeimo-html-dom-htmlelement/#property-document)
- Property [HtmlNode.Document](/api/html-core/officeimo-html-dom-htmlnode/#property-document)
- Method [IHtmlParserProvider.ParseDocument](/api/html-core/officeimo-html-dom-ihtmlparserprovider/#method-parsedocument-string-officeimo-html-dom-htmlparseoptions-threading-cancellationtoken)

### Accepted by parameters 1

- Method [HtmlDocument.Edit](/api/html-core/officeimo-html-dom-htmldocument/#method-edit-action-officeimo-html-dom-htmldocument) parameter `edit`

Filter members 

Show inherited

## Constructors

`public HtmlDocument(IHtmlDomServices services, string providerId, HtmlDocumentMode mode = Standards)` [#](#constructor-ctor-officeimo-html-dom-ihtmldomservices-string-officeimo-html-dom-htmldocumentmode)

[HtmlDocument.cs:6](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlDocument.cs#L6)

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()` [#](#method-clone)

[HtmlDocument.cs:126](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlDocument.cs#L126)

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

Returns

`HtmlDocument`

`public HtmlDocument CloneAttached(CancellationToken cancellationToken = default)` [#](#method-cloneattached-threading-cancellationtoken)

[HtmlDocument.cs:106](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlDocument.cs#L106)

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.

Returns

`HtmlDocument`

`public HtmlNode CreateComment(string text)` [#](#method-createcomment-string)

[HtmlDocument.cs:46](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlDocument.cs#L46)

Creates a comment in this mutable document.

Parameters

**text string required**

Returns

`HtmlNode`

`public HtmlDocumentType CreateDocumentType(string name, string publicIdentifier = "", string systemIdentifier = "")` [#](#method-createdocumenttype-string-string-string)

[HtmlDocument.cs:54](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlDocument.cs#L54)

Creates a document type with the supplied identifiers.

Parameters

**name string required**

**publicIdentifier string = "" optional**

**systemIdentifier string = "" optional**

Returns

`HtmlDocumentType`

`public HtmlElement CreateElement(string localName, string namespaceUri = "http://www.w3.org/1999/xhtml", string? prefix = null)` [#](#method-createelement-string-string-string)

[HtmlDocument.cs:37](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlDocument.cs#L37)

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**

Returns

`HtmlElement`

`public HtmlDocumentFragment CreateFragment()` [#](#method-createfragment)

[HtmlDocument.cs:49](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlDocument.cs#L49)

Creates a detached fragment in this mutable document.

Returns

`HtmlDocumentFragment`

`public HtmlNode CreateTextNode(string text)` [#](#method-createtextnode-string)

[HtmlDocument.cs:44](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlDocument.cs#L44)

Creates decoded text in this mutable document.

Parameters

**text string required**

Returns

`HtmlNode`

`public HtmlDocument Edit(Action<HtmlDocument> edit)` [#](#method-edit-action-officeimo-html-dom-htmldocument)

[HtmlDocument.cs:145](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlDocument.cs#L145)

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

Parameters

**edit System.Action<OfficeIMO.Html.Dom.HtmlDocument> required**

Returns

`HtmlDocument`

`public HtmlDocument Freeze()` [#](#method-freeze)

[HtmlDocument.cs:123](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlDocument.cs#L123)

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

Returns

`HtmlDocument`

`public HtmlNode? GetNode(int nodeId)` [#](#method-getnode-int32)

[HtmlDocument.cs:78](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlDocument.cs#L78)

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

Parameters

**nodeId int required**

Returns

`HtmlNode?`

`public HtmlDocumentFragment GetOrCreateTemplateContent(HtmlElement template)` [#](#method-getorcreatetemplatecontent-officeimo-html-dom-htmlelement)

[HtmlDocument.cs:59](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlDocument.cs#L59)

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

Parameters

**template OfficeIMO.Html.Dom.HtmlElement required**

Returns

`HtmlDocumentFragment`

`public HtmlNode ImportNode(HtmlNode source, bool deep = true, CancellationToken cancellationToken = default)` [#](#method-importnode-officeimo-html-dom-htmlnode-boolean-threading-cancellationtoken)

[HtmlDocument.Import.cs:18](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlDocument.Import.cs#L18)

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)` [#](#method-setsourceindex-officeimo-html-dom-htmlnode-nullable-system-int32)

[HtmlDocument.cs:71](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlDocument.cs#L71)

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

Parameters

**node OfficeIMO.Html.Dom.HtmlNode required**

**sourceIndex int? required**

## Inherited Methods

`public HtmlNode AppendChild(HtmlNode child)` [#](#method-appendchild-htmlnode)

[HtmlNode.cs:74](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlNode.cs#L74)

Inherited from [HtmlNode](/api/html-core/officeimo-html-dom-htmlnode/)

Parameters

**child HtmlNode required**

Returns

`HtmlNode`

`public IEnumerable<HtmlNode> Descendants()` [#](#method-descendants)

Inherited from [HtmlNode](/api/html-core/officeimo-html-dom-htmlnode/)

Returns

`IEnumerable<HtmlNode>`

`public virtual bool Equals(object? obj)` [#](#method-equals-object)

Inherited from object

Parameters

**obj object? required**

Returns

`bool`

`public virtual int GetHashCode()` [#](#method-gethashcode)

Inherited from object

Returns

`int`

`public Type GetType()` [#](#method-gettype)

Inherited from object

Returns

`Type`

`public HtmlElement? QuerySelector(string selector)` [#](#method-queryselector-string)

[HtmlNode.cs:122](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlNode.cs#L122)

Inherited from [HtmlNode](/api/html-core/officeimo-html-dom-htmlnode/)

Parameters

**selector string required**

Returns

`HtmlElement?`

`public IReadOnlyList<HtmlElement> QuerySelectorAll(string selector)` [#](#method-queryselectorall-string)

[HtmlNode.cs:125](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlNode.cs#L125)

Inherited from [HtmlNode](/api/html-core/officeimo-html-dom-htmlnode/)

Parameters

**selector string required**

Returns

`IReadOnlyList<HtmlElement>`

`public void Remove()` [#](#method-remove)

[HtmlNode.cs:103](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlNode.cs#L103)

Inherited from [HtmlNode](/api/html-core/officeimo-html-dom-htmlnode/)

`public virtual string? ToString()` [#](#method-tostring)

Inherited from object

Returns

`string?`

## Properties

`public Guid SnapshotId { get; }` [#](#property-snapshotid)

[HtmlDocument.cs:17](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlDocument.cs#L17)

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

`public long Revision { get; private set; }` [#](#property-revision)

[HtmlDocument.cs:19](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlDocument.cs#L19)

Mutation revision used to invalidate derived state.

`public bool IsReadOnly { get; private set; }` [#](#property-isreadonly)

[HtmlDocument.cs:21](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlDocument.cs#L21)

Whether this tree rejects further mutation, including detached nodes.

`public string ProviderId { get; }` [#](#property-providerid)

[HtmlDocument.cs:23](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlDocument.cs#L23)

Parser identity attached when the tree was created.

`public HtmlDocumentMode Mode { get; }` [#](#property-mode)

[HtmlDocument.cs:25](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlDocument.cs#L25)

Layout compatibility mode established by the parser.

`public IHtmlDomServices Services { get; }` [#](#property-services)

[HtmlDocument.cs:27](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlDocument.cs#L27)

Syntax services used for queries and serialization.

`public HtmlElement? DocumentElement { get; }` [#](#property-documentelement)

[HtmlDocument.cs:29](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlDocument.cs#L29)

Root element, if present.

`public HtmlElement? Body { get; }` [#](#property-body)

[HtmlDocument.cs:31](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlDocument.cs#L31)

Direct HTML body or frameset child of the root.

`public HtmlElement? Head { get; }` [#](#property-head)

[HtmlDocument.cs:33](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlDocument.cs#L33)

Direct HTML head child of the root.

## Inherited Properties

`public HtmlDocument Document { get; }` [#](#property-document)

[HtmlNode.cs:22](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlNode.cs#L22)

Inherited from [HtmlNode](/api/html-core/officeimo-html-dom-htmlnode/)

`public int NodeId { get; }` [#](#property-nodeid)

[HtmlNode.cs:24](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlNode.cs#L24)

Inherited from [HtmlNode](/api/html-core/officeimo-html-dom-htmlnode/)

`public HtmlNodeKind Kind { get; }` [#](#property-kind)

[HtmlNode.cs:26](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlNode.cs#L26)

Inherited from [HtmlNode](/api/html-core/officeimo-html-dom-htmlnode/)

`public HtmlNode? Parent { get; }` [#](#property-parent)

[HtmlNode.cs:28](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlNode.cs#L28)

Inherited from [HtmlNode](/api/html-core/officeimo-html-dom-htmlnode/)

`public HtmlElement? ParentElement { get; }` [#](#property-parentelement)

[HtmlNode.cs:31](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlNode.cs#L31)

Inherited from [HtmlNode](/api/html-core/officeimo-html-dom-htmlnode/)

`public IReadOnlyList<HtmlNode> ChildNodes { get; }` [#](#property-childnodes)

[HtmlNode.cs:33](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlNode.cs#L33)

Inherited from [HtmlNode](/api/html-core/officeimo-html-dom-htmlnode/)

`public IEnumerable<HtmlElement> Children { get; }` [#](#property-children)

[HtmlNode.cs:35](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlNode.cs#L35)

Inherited from [HtmlNode](/api/html-core/officeimo-html-dom-htmlnode/)

`public HtmlNode? FirstChild { get; }` [#](#property-firstchild)

[HtmlNode.cs:37](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlNode.cs#L37)

Inherited from [HtmlNode](/api/html-core/officeimo-html-dom-htmlnode/)

`public HtmlNode? NextSibling { get; }` [#](#property-nextsibling)

[HtmlNode.cs:39](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlNode.cs#L39)

Inherited from [HtmlNode](/api/html-core/officeimo-html-dom-htmlnode/)

`public HtmlNode? PreviousSibling { get; }` [#](#property-previoussibling)

[HtmlNode.cs:41](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlNode.cs#L41)

Inherited from [HtmlNode](/api/html-core/officeimo-html-dom-htmlnode/)

`public int? SourceIndex { get; internal set; }` [#](#property-sourceindex)

[HtmlNode.cs:43](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlNode.cs#L43)

Inherited from [HtmlNode](/api/html-core/officeimo-html-dom-htmlnode/)

`public virtual string NodeName { get; }` [#](#property-nodename)

[HtmlNode.cs:45](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlNode.cs#L45)

Inherited from [HtmlNode](/api/html-core/officeimo-html-dom-htmlnode/)

`public string TextContent { get; set; }` [#](#property-textcontent)

[HtmlNode.cs:49](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlNode.cs#L49)

Inherited from [HtmlNode](/api/html-core/officeimo-html-dom-htmlnode/)

`public string OuterHtml { get; }` [#](#property-outerhtml)

[HtmlNode.cs:68](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlNode.cs#L68)

Inherited from [HtmlNode](/api/html-core/officeimo-html-dom-htmlnode/)

`public string InnerHtml { get; }` [#](#property-innerhtml)

[HtmlNode.cs:70](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlNode.cs#L70)

Inherited from [HtmlNode](/api/html-core/officeimo-html-dom-htmlnode/)

<!-- PowerForge markdown artifact sha256:686F173FED7AD04F1D4E2EF176B775385EBB0BA0558310F2C2B3AB70B6866393 -->
