HtmlDocument
OfficeIMO.Html.Dom
An owned HTML tree with explicit snapshot and mutation semantics. Mutable documents require a single owner.
Inheritance
- 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
- Method HtmlDocument.CloneAttached
- Method HtmlDocument.Edit
- Method HtmlDocument.Freeze
- Property HtmlDocument.Document
- Property HtmlDocumentFragment.Document
- Property HtmlDocumentType.Document
- Property HtmlElement.Document
- Property HtmlNode.Document
- Method IHtmlParserProvider.ParseDocument
Accepted by parameters 1
- Method HtmlDocument.Edit
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
- providerId string
- mode OfficeIMO.Html.Dom.HtmlDocumentMode = Standards
Methods
public HtmlDocument Clone() #Creates an independent mutable clone, preserving node IDs and source positions.
Returns
HtmlDocumentpublic 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
- Cooperative cancellation while copying nodes and attributes.
Returns
HtmlDocumentpublic HtmlNode CreateComment(string text) #Creates a comment in this mutable document.
Parameters
- text string
Returns
HtmlNodepublic HtmlDocumentType CreateDocumentType(string name, string publicIdentifier = "", string systemIdentifier = "") #Creates a document type with the supplied identifiers.
Parameters
- name string
- publicIdentifier string = ""
- systemIdentifier string = ""
Returns
HtmlDocumentTypepublic 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
- namespaceUri string = "http://www.w3.org/1999/xhtml"
- prefix string? = null
Returns
HtmlElementpublic HtmlDocumentFragment CreateFragment() #Creates a detached fragment in this mutable document.
Returns
HtmlDocumentFragmentpublic HtmlNode CreateTextNode(string text) #Creates decoded text in this mutable document.
Parameters
- text string
Returns
HtmlNodepublic HtmlDocument Edit(Action<HtmlDocument> edit) #Applies edits to an independent clone and freezes the returned snapshot.
Parameters
- edit System.Action<OfficeIMO.Html.Dom.HtmlDocument>
Returns
HtmlDocumentpublic HtmlDocument Freeze() #Freezes this instance. Every retained node handle becomes read-only.
Returns
HtmlDocumentpublic HtmlNode? GetNode(int nodeId) #Finds a node by its document-local identity, including detached nodes.
Parameters
- nodeId int
Returns
HtmlNode?public HtmlDocumentFragment GetOrCreateTemplateContent(HtmlElement template) #Creates or returns this template element's separate content fragment.
Parameters
- template OfficeIMO.Html.Dom.HtmlElement
Returns
HtmlDocumentFragmentpublic 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
- An element, text, comment, document type or fragment from any owned document.
- deep bool = true
- Whether to include descendants and template contents.
- cancellationToken System.Threading.CancellationToken = default
- Cooperative cancellation while copying nodes.
Returns
HtmlNodepublic void SetSourceIndex(HtmlNode node, int? sourceIndex) #Attaches an original UTF-16 source position while constructing a mutable tree.
Parameters
- node OfficeIMO.Html.Dom.HtmlNode
- sourceIndex int?
Inherited Methods
public HtmlNode AppendChild(HtmlNode child) #Parameters
- child HtmlNode
Returns
HtmlNodepublic HtmlElement? QuerySelector(string selector) #Parameters
- selector string
Returns
HtmlElement?public IReadOnlyList<HtmlElement> QuerySelectorAll(string selector) #Parameters
- selector string
Returns
IReadOnlyList<HtmlElement>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? Body { get; } #Direct HTML body or frameset child of the root.