(*--------------------------------------------------------------------------- Copyright (c) 2025 Anil Madhavapeddy . All rights reserved. SPDX-License-Identifier: MIT ---------------------------------------------------------------------------*) (** HTML5 DOM Node Types and Operations This module provides the DOM (Document Object Model) node representation used by the HTML5 parser. The DOM is a programming interface that represents an HTML document as a tree of nodes, where each node represents part of the document (an element, text content, comment, etc.). {2 What is the DOM?} When an HTML parser processes markup like [

Hello world

], it doesn't store the text directly. Instead, it builds a tree structure in memory: {v Document └── html └── body └── p ├── #text "Hello " └── b └── #text "world" v} This tree is the DOM. Each box in the tree is a {i node}. Programs can traverse and modify this tree to read or change the document. @see WHATWG: The elements of HTML (DOM chapter) {2 Node Types} The HTML5 DOM includes several node types, all represented by the same record type with different field usage: - {b Element nodes}: HTML elements like [
], [

], []. Elements are the building blocks of HTML documents. They can have attributes and contain other nodes. - {b Text nodes}: The actual text content within elements. For example, in [

Hello

], "Hello" is a text node that is a child of the [

] element. - {b Comment nodes}: HTML comments written as []. Comments are preserved in the DOM but not rendered. - {b Document nodes}: The root of the entire document tree. Every HTML document has exactly one Document node at the top. - {b Document fragment nodes}: Lightweight containers that hold a collection of nodes without a parent. Used for efficient batch DOM operations and [