A simple reference-counted DOM.
This is sufficient as a static parse tree, but don't build a web browser using it. :)
A DOM is a tree structure with ordered children that can be represented in an XML-like format. For example, the following graph
div +- "text node" +- span
in HTML would be serialized as
See the document object model article on wikipedia for more information.
This implementation stores the information associated with each node once, and then hands out refs to children. The nodes themselves are reference-counted to avoid copying - you can create a new ref and then a node will outlive the document. Nodes own their children, but only have weak references to their parents.
The DOM itself; the result of parsing.
A DOM node.
The different kinds of nodes in the DOM.
Reference to a DOM node.
Weak reference to a DOM node, used for parent pointers.