API Reference

Complete API reference for the dawm library — parsing, DOM classes, serialization, and more.


Parsing

parseHTML

Parse an HTML string into a Document.

import { parseHTML } from "dawm";

parseHTML(input: string, options?: ParseOptions | null): Document;

Parameters:

Returns: A Document instance.


parseDocument

Parse a string as either HTML or XML, depending on the content type.

import { parseDocument } from "dawm";

parseDocument(input: string, options?: ParseOptions | null): Document;
parseDocument(input: string, mimeType: string, options?: ParseOptions | null): Document;

Parameters:


parseFragment

Parse an HTML fragment within a given context element.

import { parseFragment } from "dawm/parse";

parseFragment(input: string, options: FragmentParseOptions | null): DocumentFragment;
parseFragment(input: string, contextElement: string, options?: ParseOptions | null): DocumentFragment;

Parameters:


DOMParser

Standards-compliant DOMParser implementation.

import { DOMParser } from "dawm";

const parser = new DOMParser();
const doc = parser.parseFromString("<p>Hello</p>", "text/html");

Document.parseHTML

Static method on Document for parsing HTML.

import { Document } from "dawm";

const doc = Document.parseHTML("<html><body><p>Hello</p></body></html>");

Document.parseXML

Static method on Document for parsing XML.

import { Document } from "dawm";

const doc = Document.parseXML("<root><item>1</item></root>");

Core DOM Classes

Document

The root of the DOM tree. Extends Node.

Key properties:

Key methods:


Element

Represents an HTML/XML element. Extends Node.

Key properties:

Key methods:


Node

The base class for all DOM nodes.

Key properties:

Key methods:


Attr

Represents an attribute on an element.

Properties: name, value, ownerElement, namespaceURI, prefix, localName.


Text

Represents a text node. Extends CharacterData.


Comment

Represents an HTML comment. Extends CharacterData.


CDATASection

Represents a CDATA section (XML). Extends Text.


ProcessingInstruction

Represents a processing instruction (e.g., <?xml ...?>). Extends CharacterData.


DocumentFragment

A lightweight document used for building DOM subtrees before insertion.


DocumentType

Represents the <!DOCTYPE> declaration.

Properties: name, publicId, systemId.


Collections

NodeList

An ordered collection of nodes. Returned by querySelectorAll and childNodes.

Methods: item(index), forEach(callback), entries(), keys(), values().


HTMLCollection

A live collection of elements. Returned by getElementsByTagName, children, etc.

Methods: item(index), namedItem(name).


NamedNodeMap

An unordered collection of Attr nodes. Available via element.attributes.

Methods: getNamedItem(name), setNamedItem(attr), removeNamedItem(name), item(index).


DOMTokenList

A set of space-separated tokens. Used by element.classList.

Methods: add(token), remove(token), toggle(token), contains(token), replace(old, new).


DOMStringMap

Access data-* attributes as properties. Available via element.dataset.


Serialization

XMLSerializer

Serialize DOM trees back to markup strings.

import { XMLSerializer } from "dawm/serialize";

const serializer = new XMLSerializer();
const html = serializer.serializeToString(document);

Element.outerHTML

Get the serialized HTML of an element including its tag:

console.log(element.outerHTML);
// "<div class="example">content</div>"

Element.innerHTML

Get or set the serialized HTML of an element’s contents:

element.innerHTML = "<p>New content</p>";
console.log(element.innerHTML);

Implementation Status

Fully Implemented

APIStatus
Node, Element, Attr
Text, Comment, CDATASection
ProcessingInstruction
Document, DocumentFragment, DocumentType
NodeList, HTMLCollection, NamedNodeMap
DOMTokenList, DOMStringMap
DOMParser, XMLSerializer
Document.parseHTML, Document.parseXML
querySelector, querySelectorAll

Planned

APIStatus
Element.setHTML🔜 Planned
Element.getHTML🔜 Planned
Element.insertAdjacentHTML🔜 Planned
StyleSheetList, MediaList🔜 Planned