parserino.dom
The document tree.
Every node lives in the arena of its document and is freed with it: removed nodes stay valid. Nodes are plain structs: DomElement, DomCharacterData, ... start with a DomNode: node.as!DomElement (after checking type) gives the struct that contains it.
Types 9
enumNodeType : ubyte
Node types, with the values of DOM nodeType
Element = 1
Text = 3
CDataSection = 4
ProcessingInstruction = 7
Comment = 8
Document = 9
DocumentType = 10
DocumentFragment = 11
enumCompatMode : ubyte
Quirks mode of a document, set by the parser from the doctype
NoQuirks
LimitedQuirks
Quirks
structDomNode
The common part of all the nodes
Fields
NodeType typeNs nsuint nameTag of elements (a `Tag` or an id from the document names). Other nodes: `Tag.TextNode`, `Tag.CommentNode`, ...DomNode * parentDomNode * firstChildDomNode * lastChildDomNode * prevDomNode * nextDomDocument * documentMethods
bool isHtml(uint tag) @nogc nothrow pure @safe constIs this an element in the html namespace with this tag?T * as(T)() @nogc nothrow pure @safe @trusted returnThe struct that contains this node: `DomElement`, `DomCharacterData`, `DomDocumentType`, `DomDocumentFragment` or `DomDocument`. `type` must match (checked only by an assert).DomElement * asElement() @nogc nothrow pure @safe returnThe element / character data, or null if the node is something elsebool isCharacterData() @nogc nothrow pure @safe constIs it text, a comment, a processing instruction or a CDATA section?void appendChild(DomNode * child) @nogc nothrow pure @safeAppend `child` as the last child (`child` must be detached)void moveChildrenTo(DomNode * to) @nogc nothrow pure @safeMove all the children of this node at the end of `to`auto parentOrHost(this This)() @nogc nothrow pure @safeThe parent, or the `<template>` for the nodes of a template contentauto firstChildOrContent(this This)() @nogc nothrow pure @safeThe first node of the template content for a `<template>`, else the first childbool contains(const(DomNode) * other) @nogc nothrow pure @safe constIs `other` this node or one of its descendants?auto nextInTree(this This)(const(DomNode) * root) @nogc nothrow pure @safeNext node in tree order inside `root` (excluded), or nullauto nextSkippingChildren(this This)(const(DomNode) * root) @nogc nothrow pure @safeNext node in tree order after this subtree, inside `root`, or nullconst(char)[] localName() @nogc nothrow pure @safe constLocal name ("div", "#text", "!--", ...; the target for processing instructions)bool isEmpty() @nogc nothrow pure @safe constDoes it have no children that are elements or non-empty text? Comments and processing instructions don't count (as for the `:empty` selector).bool isBlank() @nogc nothrow pure @safe constLike `isEmpty`, but text made only of whitespace doesn't count either (the `:blank` selector)structDomAttribute
An attribute
Fields
uint nameLocal name, lowercase (an `AttrName` or an id from the document names)Ns nsconst(char)[] qualifiedNameThe name to serialize, when it differs from the local name (`xlink:href`, `viewBox`), else nullconst(char)[] valueDomElement * ownerDomAttribute * prevDomAttribute * nextstructDomElement
An element
Fields
DomNode nodeconst(char)[] qualifiedNameThe name to serialize, when it differs from the local name (`foreignObject`), else nullDomAttribute * firstAttrDomAttribute * lastAttrDomAttribute * idAttrDomAttribute * classAttrDomDocumentFragment * templateContentThe content of a `<template>`ubyte flagsState used by the parser (option selectedness, ...)Methods
const(char)[] fullName() @nogc nothrow pure @safe constTag name as written in html: `div`, `foreignObject`CopyConstness!(This, DomAttribute) * attribute(this This)(uint id) @nogc nothrow pure @safeFirst attribute with this (lowercase) name id, any namespaceCopyConstness!(This, DomAttribute) * attribute(this This)(scope const(char)[] name) @nogc nothrow pure @safeFirst attribute with this name (case-insensitive for html elements)void appendAttribute(DomAttribute * a) @nogc nothrow pure @safeAppend an attribute (no duplicate check)structDomCharacterData
Text, comments, processing instructions, CDATA sections
Methods
void borrowData(return scope const(char)[] s) @nogc nothrow pure @safe @trustedUse `s` as the text, without copying it: `s` must outlive the document and never change (it's never written: a later change of the text reallocates it).bool appendData(scope const(char)[] s) @nogc nothrow pure @safe @trustedAppend to the text. It returns false if out of memory.structDomDocumentType
A doctype: <!DOCTYPE name PUBLIC "publicId" "systemId">
structDomDocumentFragment
A fragment, or the content of a <template>
structDomDocument
The document: it owns the memory of all its nodes (and the names it meets). It can't be copied: allocate it zeroed, call initialize, and release it at the end.
Methods
auto head(this This)() @nogc nothrow pure @safeThe `<head>`: the first `head` child of the `<html>` root element (as in the standard)auto body(this This)() @nogc nothrow pure @safeThe `<body>`: the first `body` or `frameset` child of the `<html>` root element (as in the standard)void initialize() @nogc nothrow pure @safeInitialize a document allocated by the caller (zeroed memory)uint tagId(scope const(char)[] lowerName) @nogc nothrow pure @safeTag id of a lowercase name, adding it if unknown. 0 if out of memory.uint findTagName(scope const(char)[] name) @nogc nothrow pure @safe constTag id of a name (any case), 0 if the document never saw ituint attrId(scope const(char)[] lowerName) @nogc nothrow pure @safeAttribute id of a lowercase name, adding it if unknown. 0 if out of memory.uint findAttrName(scope const(char)[] name) @nogc nothrow pure @safe constAttribute id of a name (any case), 0 if the document never saw itDomElement * createElement(uint tag, Ns ns) @nogc nothrow pure @safeA new element (not attached), with an empty content for a `<template>`. It returns null if out of memory, as the other `create...` functions.DomCharacterData * createText(scope const(char)[] data) @nogc nothrow pure @safeA new text node (not attached), with a copy of `data`DomCharacterData * createComment(scope const(char)[] data) @nogc nothrow pure @safeA new comment (not attached), with a copy of `data`DomCharacterData * createProcessingInstruction(scope const(char)[] target, scope const(char)[] data) @nogc nothrow pure @safeA new processing instruction (not attached)DomDocumentType * createDocumentType(scope const(char)[] name, scope const(char)[] publicId, scope const(char)[] systemId) @nogc nothrow pure @safeA new doctype (not attached)DomAttribute * createAttribute(scope const(char)[] lowerName, scope const(char)[] value, Ns ns = Ns.None) @nogc nothrow pure @safeA new attribute (not attached). The name must be lowercase.DomAttribute * createAttribute(uint id, scope const(char)[] value, Ns ns = Ns.None) @nogc nothrow pure @safedittoDomAttribute * setAttribute(DomElement * e, scope const(char)[] name, scope const(char)[] value) @nogc nothrow pure @safeSet (or add) an attribute. The name is lowercased. It returns null if out of memory.DomNode * importNode(const(DomNode) * src, bool deep) @nogc nothrow pure @safeA copy of `src` owned by this document. Deep: with all the descendants and the template contents; else only the node (and the attributes). It returns null if out of memory. The visit is iterative, ...Functions 2
fn
void textContent(Sink)(const(DomNode) * node, ref Sink sink)The text of a node and its descendants (DOM `textContent`) written to `sink`