elisp: Document Object Model

 
 31.26.1 Document Object Model
 -----------------------------
 
 The DOM returned by ‘libxml-parse-html-region’ (and the other XML
 parsing functions) is a tree structure where each node has a node name
 (called a “tag”), and optional key/value “attribute” list, and then a
 list of “child nodes”.  The child nodes are either strings or DOM
 objects.
 
      (body ((width . "101"))
       (div ((class . "thing"))
        "Foo"
        (div nil
         "Yes")))
 
  -- Function: dom-node tag &optional attributes &rest children
      This function creates a DOM node of type TAG.  If given, ATTRIBUTES
      should be a key/value pair list.  If given, CHILDREN should be DOM
      nodes.
 
    The following functions can be used to work with this structure.
 Each function takes a DOM node, or a list of nodes.  In the latter case,
 only the first node in the list is used.
 
    Simple accessors:
 
 ‘dom-tag NODE’
      Return the “tag” (also called “node name”) of the node.
 
 ‘dom-attr NODE ATTRIBUTE’
      Return the value of ATTRIBUTE in the node.  A common usage would
      be:
 
           (dom-attr img 'href)
           => "http://fsf.org/logo.png"
 
 ‘dom-children NODE’
      Return all the children of the node.
 
 ‘dom-non-text-children NODE’
      Return all the non-string children of the node.
 
 ‘dom-attributes NODE’
      Return the key/value pair list of attributes of the node.
 
 ‘dom-text NODE’
      Return all the textual elements of the node as a concatenated
      string.
 
 ‘dom-texts NODE’
      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.
 
 ‘dom-parent DOM NODE’
      Return the parent of NODE in DOM.
 
    The following are functions for altering the DOM.
 
 ‘dom-set-attribute NODE ATTRIBUTE VALUE’
      Set the ATTRIBUTE of the node to VALUE.
 
 ‘dom-append-child NODE CHILD’
      Append CHILD as the last child of NODE.
 
 ‘dom-add-child-before NODE CHILD BEFORE’
      Add CHILD to NODE’s child list before the BEFORE node.  If BEFORE
      is ‘nil’, make CHILD the first child.
 
 ‘dom-set-attributes NODE ATTRIBUTES’
      Replace all the attributes of the node with a new key/value list.
 
    The following are functions for searching for elements in the DOM.
 They all return lists of matching nodes.
 
 ‘dom-by-tag DOM TAG’
      Return all nodes in DOM that are of type TAG.  A typical use would
      be:
 
           (dom-by-tag dom 'td)
           => '((td ...) (td ...) (td ...))
 
 ‘dom-by-class DOM MATCH’
      Return all nodes in DOM that have class names that match MATCH,
      which is a regular expression.
 
 ‘dom-by-style DOM STYLE’
      Return all nodes in DOM that have styles that match MATCH, which is
      a regular expression.
 
 ‘dom-by-id DOM STYLE’
      Return all nodes in DOM that have IDs that match MATCH, which is a
      regular expression.
 
 ‘dom-strings DOM’
      Return all strings in DOM.
 
    Utility functions:
 
 ‘dom-pp DOM &optional REMOVE-EMPTY’
      Pretty-print DOM at point.  If REMOVE-EMPTY, don’t print textual
      nodes that just contain white-space.