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:
input— The HTML string to parse.options— OptionalParseOptionsto customize parsing behavior.
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:
input— The string to parse.mimeType— Optional MIME type ("text/html"or"application/xml").options— Optional parse options.
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:
input— The HTML fragment string.contextElement— The tag name of the context element (e.g.,"ul","table").options— Optional parse options.
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:
documentElement— The root<html>element.head— The<head>element.body— The<body>element.title— The document title (read/write).doctype— TheDocumentTypenode.
Key methods:
getElementById(id)— Find element by ID.getElementsByClassName(className)— Find elements by class name.getElementsByName(name)— Find elements bynameattribute.getElementsByTagName(tagName)— Find elements by tag name.getElementsByTagNameNS(namespace, tagName)— Find elements by namespace and tag.querySelector(selector)— Find first element matching CSS selector.querySelectorAll(selector)— Find all elements matching CSS selector.createElement(tagName)— Create a new element.createTextNode(text)— Create a new text node.
Element
Represents an HTML/XML element. Extends Node.
Key properties:
tagName— The element’s tag name (uppercase for HTML).id— The element’sidattribute.className— The element’sclassattribute.classList— ADOMTokenListfor class manipulation.attributes— ANamedNodeMapof all attributes.innerHTML— The element’s inner HTML (read/write).outerHTML— The element’s outer HTML (read/write).textContent— The element’s text content (read/write).dataset— ADOMStringMapfor data attributes.children— AnHTMLCollectionof child elements.firstElementChild/lastElementChild— First/last child element.nextElementSibling/previousElementSibling— Adjacent siblings.
Key methods:
getAttribute(name)/setAttribute(name, value)— Get/set attributes.hasAttribute(name)/removeAttribute(name)— Check/remove attributes.querySelector(selector)/querySelectorAll(selector)— CSS selector queries.getElementsByClassName(className)— Find descendants by class.getElementsByTagName(tagName)— Find descendants by tag.appendChild(node)— Append a child node.removeChild(node)— Remove a child node.
Node
The base class for all DOM nodes.
Key properties:
nodeType— The type of node (e.g.,1for Element,3for Text).nodeName— The name of the node.nodeValue— The value of the node.parentNode/parentElement— The parent node/element.childNodes— ANodeListof all child nodes.firstChild/lastChild— First/last child node.nextSibling/previousSibling— Adjacent sibling nodes.
Key methods:
appendChild(node)— Append a child.removeChild(node)— Remove a child.cloneNode(deep?)— Clone the node.
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
| API | Status |
|---|---|
Node, Element, Attr | ✅ |
Text, Comment, CDATASection | ✅ |
ProcessingInstruction | ✅ |
Document, DocumentFragment, DocumentType | ✅ |
NodeList, HTMLCollection, NamedNodeMap | ✅ |
DOMTokenList, DOMStringMap | ✅ |
DOMParser, XMLSerializer | ✅ |
Document.parseHTML, Document.parseXML | ✅ |
querySelector, querySelectorAll | ✅ |
Planned
| API | Status |
|---|---|
Element.setHTML | 🔜 Planned |
Element.getHTML | 🔜 Planned |
Element.insertAdjacentHTML | 🔜 Planned |
StyleSheetList, MediaList | 🔜 Planned |