README

bobzhang/html_parser/dom does not have a README file

#
Node

pub(all) struct Node {
kind : NodeKind
name : String
ns : String?
attrs : Map[String, String?]
data : String
public_id : String?
system_id : String?
force_quirks : Bool
parsed_from_source : Bool
source_start_tag : String?
source_end_tag : String?
sanitize_escape_only : Bool
origin_offset : Int?
origin_line : Int?
origin_col : Int?
parent : Node?
children : Array[Node]
} derive(
Debug
)

DOM node used for documents, fragments, elements, text, comments, and doctypes.

Nodes are created with helpers such as document, fragment, element, text, comment, and doctype.

#
Node::append_child

fn Node::append_child(self : Node, child : Node) -> Unit

Append child to this node.

The child is detached from any existing parent first. Non-container nodes and cycle-producing appends are ignored.

#
Node::attrs

fn Node::attrs(self : Node) -> Map[String, String?]

Return a copy of this node's attributes.

#
Node::children

fn Node::children(self : Node) -> Array[Node]

Return a copy of this node's child list.

The returned array is detached from the node, but the child nodes themselves are the same node objects.

#
Node::clone_node

fn Node::clone_node(self : Node, deep? : Bool, override_attrs? : Map[String, String?]) -> Node

Clone this node.

deep=true recursively clones descendants. override_attrs replaces the cloned node's attributes, which is useful for transform operations.

#
Node::data

fn Node::data(self : Node) -> String

Return this text, comment, or doctype node's data payload.

#
Node::has_child_nodes

fn Node::has_child_nodes(self : Node) -> Bool

Test whether this node has any child nodes.

#
Node::insert_before

fn Node::insert_before(self : Node, child : Node, before : Node?) -> Unit

Insert child before before, or append when before is absent.

If before is not a current child, the child is appended. Invalid insertions are ignored in the same way as append_child.

#
Node::kind

fn Node::kind(self : Node) -> NodeKind

Return this node's kind.

#
Node::name

fn Node::name(self : Node) -> String

Return this node's name.

#
Node::namespace_uri

fn Node::namespace_uri(self : Node) -> String?

Return this element's namespace URI, if any.

#
Node::origin_col

fn Node::origin_col(self : Node) -> Int?

Return this node's original 1-based source column, if known.

#
Node::origin_line

fn Node::origin_line(self : Node) -> Int?

Return this node's original 1-based source line, if known.

#
Node::origin_location

fn Node::origin_location(self : Node) -> (Int, Int)?

Return this node's original (line, column) source location, if known.

#
Node::origin_offset

fn Node::origin_offset(self : Node) -> Int?

Return this node's original source offset, if known.

#
Node::parent

fn Node::parent(self : Node) -> Node?

Return this node's parent, if any.

#
Node::remove_child

fn Node::remove_child(self : Node, child : Node) -> Unit

Remove child from this node if it is a current child.

#
Node::replace_child

fn Node::replace_child(self : Node, new_child : Node, old_child : Node) -> Node?

Replace old_child with new_child.

Returns the removed child when replacement succeeds, or None when old_child is not a current child or the replacement would create a cycle.

#
Node::text

fn Node::text(self : Node) -> String

Return this node's descendant text with no separator and no trimming.

#
NodeKind

pub(all) enum NodeKind {
Document
Fragment
Element
Text
Comment
Doctype
} derive(Eq,
Debug
)

Kind of DOM node represented by Node.

#
comment

fn comment(data : StringView) -> Node

Create a comment node.

#
doctype

fn doctype(name? : String, public_id? : String, system_id? : String, force_quirks? : Bool) -> Node

Create a doctype node.

#
document

fn document(children? : Array[Node]) -> Node

Create a document node with optional children.

#
element

fn element(name : StringView, attrs? : Map[String, String?], children? : Array[Node], ns? : String) -> Node

Create an element node.

Namespace aliases html, svg, and mathml are normalized for serializer and sanitizer behavior. Child nodes are attached in order.

#
fragment

fn fragment(children? : Array[Node]) -> Node

Create a document-fragment node with optional children.

#
text

fn text(data : StringView) -> Node

Create a text node.

Source Files

Powered by MoonBit

Site sourceReport issuePackagesBuild queueSkillsStatistics

© 2026 mooncakes.io