A mutable XML document.
The Ruby implementation of sablon leans heavily on Nokogiri's mutable DOM:
nodes are removed, duplicated and re-parented in place while operations are
evaluated. Reproducing that faithfully is far simpler with a mutable store
than with a persistent tree, so every document owns a Sablon.XML.Store
holding its nodes. A Sablon.XML.Node is just a {document, id} pair
pointing into that store, which gives the same reference semantics Nokogiri
nodes have.
A document is process local; see Sablon.XML.Store for why.
Summary
Functions
Identifier of the implicit document node that owns all top level nodes.
The node representing the document itself.
Discards the document, freeing everything its store holds.
Parses an XML fragment. The resulting document has no single root element, the parsed nodes are direct children of the document node.
Reads a value stored with put_meta/3.
Creates a new empty document.
Parses an XML string into a document.
Stores an arbitrary value alongside the document.
The root element of the document, i.e. the first top level element node.
Returns nil for documents that only contain a prolog or text.
The concatenated text of the whole document.
Serialises the whole document back to XML.
Updates a value stored with put_meta/3, starting from default.
Types
@type t() :: %Sablon.XML.Document{store: Sablon.XML.Store.t()}
Functions
Identifier of the implicit document node that owns all top level nodes.
@spec doc_node(t()) :: Sablon.XML.Node.t()
The node representing the document itself.
@spec drop(t()) :: :ok
Discards the document, freeing everything its store holds.
Parses an XML fragment. The resulting document has no single root element, the parsed nodes are direct children of the document node.
Reads a value stored with put_meta/3.
@spec new() :: t()
Creates a new empty document.
Parses an XML string into a document.
Stores an arbitrary value alongside the document.
Used for state that Nokogiri keeps on mutable Ruby objects, such as the reference count of a merge field shared by several blocks.
@spec root(t()) :: Sablon.XML.Node.t() | nil
The root element of the document, i.e. the first top level element node.
Returns nil for documents that only contain a prolog or text.
The concatenated text of the whole document.
Serialises the whole document back to XML.
Updates a value stored with put_meta/3, starting from default.