Up: Parsing HTML/XML
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")))
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 nodedom-attr node attribute (dom-attr img 'href)
=> "https://fsf.org/logo.png"
dom-children nodedom-non-text-children nodedom-attributes nodedom-text nodedom-texts nodedom-parent dom nodedom-remove dom nodeThe following are functions for altering the DOM.
dom-set-attribute node attribute valuedom-append-child node childdom-add-child-before node child beforenil, make child the first child.
dom-set-attributes node attributesThe following are functions for searching for elements in the DOM. They all return lists of matching nodes.
dom-by-tag dom tag (dom-by-tag dom 'td)
=> '((td ...) (td ...) (td ...))
dom-by-class dom matchdom-by-style dom styledom-by-id dom styledom-strings domUtility functions:
dom-pp dom &optional remove-empty