diff options
Diffstat (limited to 'devdocs/elisp/document-object-model.html')
| -rw-r--r-- | devdocs/elisp/document-object-model.html | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/devdocs/elisp/document-object-model.html b/devdocs/elisp/document-object-model.html new file mode 100644 index 00000000..c01529dd --- /dev/null +++ b/devdocs/elisp/document-object-model.html @@ -0,0 +1,39 @@ + <h4 class="subsection">Document Object Model</h4> <p>The <acronym>DOM</acronym> returned by <code>libxml-parse-html-region</code> (and the other <acronym>XML</acronym> parsing functions) is a tree structure where each node has a node name (called a <em>tag</em>), and optional key/value <em>attribute</em> list, and then a list of <em>child nodes</em>. The child nodes are either strings or <acronym>DOM</acronym> objects. </p> <div class="example"> <pre class="example">(body ((width . "101")) + (div ((class . "thing")) + "Foo" + (div nil + "Yes"))) +</pre> +</div> <dl> <dt id="dom-node">Function: <strong>dom-node</strong> <em>tag &optional attributes &rest children</em> +</dt> <dd><p>This function creates a <acronym>DOM</acronym> node of type <var>tag</var>. If given, <var>attributes</var> should be a key/value pair list. If given, <var>children</var> should be <acronym>DOM</acronym> nodes. </p></dd> +</dl> <p>The following functions can be used to work with this structure. Each function takes a <acronym>DOM</acronym> node, or a list of nodes. In the latter case, only the first node in the list is used. </p> <p>Simple accessors: </p> <dl compact> <dt><code>dom-tag <var>node</var></code></dt> <dd> +<p>Return the <em>tag</em> (also called “node name”) of the node. </p> </dd> <dt><code>dom-attr <var>node</var> <var>attribute</var></code></dt> <dd> +<p>Return the value of <var>attribute</var> in the node. A common usage would be: </p> <div class="lisp"> <pre class="lisp">(dom-attr img 'href) +=> "https://fsf.org/logo.png" +</pre> +</div> </dd> <dt><code>dom-children <var>node</var></code></dt> <dd> +<p>Return all the children of the node. </p> </dd> <dt><code>dom-non-text-children <var>node</var></code></dt> <dd> +<p>Return all the non-string children of the node. </p> </dd> <dt><code>dom-attributes <var>node</var></code></dt> <dd> +<p>Return the key/value pair list of attributes of the node. </p> </dd> <dt><code>dom-text <var>node</var></code></dt> <dd> +<p>Return all the textual elements of the node as a concatenated string. </p> </dd> <dt><code>dom-texts <var>node</var></code></dt> <dd> +<p>Return all the textual elements of the node, as well as the textual elements of all the children of the node, recursively, as a concatenated string. This function also takes an optional separator to be inserted between the textual elements. </p> </dd> <dt><code>dom-parent <var>dom</var> <var>node</var></code></dt> <dd> +<p>Return the parent of <var>node</var> in <var>dom</var>. </p> </dd> <dt><code>dom-remove <var>dom</var> <var>node</var></code></dt> <dd><p>Remove <var>node</var> from <var>dom</var>. </p></dd> </dl> <p>The following are functions for altering the <acronym>DOM</acronym>. </p> <dl compact> <dt><code>dom-set-attribute <var>node</var> <var>attribute</var> <var>value</var></code></dt> <dd> +<p>Set the <var>attribute</var> of the node to <var>value</var>. </p> </dd> <dt><code>dom-remove-attribute <var>node</var> <var>attribute</var></code></dt> <dd> +<p>Remove <var>attribute</var> from <var>node</var>. </p> </dd> <dt><code>dom-append-child <var>node</var> <var>child</var></code></dt> <dd> +<p>Append <var>child</var> as the last child of <var>node</var>. </p> </dd> <dt><code>dom-add-child-before <var>node</var> <var>child</var> <var>before</var></code></dt> <dd> +<p>Add <var>child</var> to <var>node</var>’s child list before the <var>before</var> node. If <var>before</var> is <code>nil</code>, make <var>child</var> the first child. </p> </dd> <dt><code>dom-set-attributes <var>node</var> <var>attributes</var></code></dt> <dd><p>Replace all the attributes of the node with a new key/value list. </p></dd> </dl> <p>The following are functions for searching for elements in the <acronym>DOM</acronym>. They all return lists of matching nodes. </p> <dl compact> <dt><code>dom-by-tag <var>dom</var> <var>tag</var></code></dt> <dd> +<p>Return all nodes in <var>dom</var> that are of type <var>tag</var>. A typical use would be: </p> <div class="lisp"> <pre class="lisp">(dom-by-tag dom 'td) +=> '((td ...) (td ...) (td ...)) +</pre> +</div> </dd> <dt><code>dom-by-class <var>dom</var> <var>match</var></code></dt> <dd> +<p>Return all nodes in <var>dom</var> that have class names that match <var>match</var>, which is a regular expression. </p> </dd> <dt><code>dom-by-style <var>dom</var> <var>style</var></code></dt> <dd> +<p>Return all nodes in <var>dom</var> that have styles that match <var>match</var>, which is a regular expression. </p> </dd> <dt><code>dom-by-id <var>dom</var> <var>style</var></code></dt> <dd> +<p>Return all nodes in <var>dom</var> that have IDs that match <var>match</var>, which is a regular expression. </p> </dd> <dt><code>dom-search <var>dom</var> <var>predicate</var></code></dt> <dd> +<p>Return all nodes in <var>dom</var> where <var>predicate</var> returns a non-<code>nil</code> value. <var>predicate</var> is called with the node to be tested as its parameter. </p> </dd> <dt><code>dom-strings <var>dom</var></code></dt> <dd> +<p>Return all strings in <var>dom</var>. </p> </dd> </dl> <p>Utility functions: </p> <dl compact> <dt><code>dom-pp <var>dom</var> &optional <var>remove-empty</var></code></dt> <dd> +<p>Pretty-print <var>dom</var> at point. If <var>remove-empty</var>, don’t print textual nodes that just contain white-space. </p> </dd> <dt><code>dom-print <var>dom</var> &optional <var>pretty</var> <var>xml</var></code></dt> <dd><p>Print <var>dom</var> at point. If <var>xml</var> is non-<code>nil</code>, print as <acronym>XML</acronym>; otherwise, print as <acronym>HTML</acronym>. If <var>pretty</var> is non-<code>nil</code>, indent the <acronym>HTML</acronym>/<acronym>XML</acronym> logically. </p></dd> </dl><div class="_attribution"> + <p class="_attribution-p"> + Copyright © 1990-1996, 1998-2022 Free Software Foundation, Inc. <br>Licensed under the GNU GPL license.<br> + <a href="https://www.gnu.org/software/emacs/manual/html_node/elisp/Document-Object-Model.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Document-Object-Model.html</a> + </p> +</div> |
