aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Magne Ingebrigtsen2014-11-26 20:23:06 +0100
committerLars Magne Ingebrigtsen2014-11-26 20:23:06 +0100
commit97d6e7e71182a421050601db662ee95c5b2cc172 (patch)
tree606583c2fae5e6e024b388d1a6069a0e4670a0ba
parentf054f0f265a09adde84c9f543d0a2f810cdafe8e (diff)
downloademacs-97d6e7e71182a421050601db662ee95c5b2cc172.tar.gz
emacs-97d6e7e71182a421050601db662ee95c5b2cc172.zip
* text.texi (Document Object Model): New node to document dom.el.
-rw-r--r--doc/lispref/ChangeLog4
-rw-r--r--doc/lispref/text.texi120
2 files changed, 123 insertions, 1 deletions
diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog
index b0da266d53a..37f16a132c3 100644
--- a/doc/lispref/ChangeLog
+++ b/doc/lispref/ChangeLog
@@ -1,3 +1,7 @@
12014-11-26 Lars Magne Ingebrigtsen <larsi@gnus.org>
2
3 * text.texi (Document Object Model): New node to document dom.el.
4
12014-11-24 Lars Magne Ingebrigtsen <larsi@gnus.org> 52014-11-24 Lars Magne Ingebrigtsen <larsi@gnus.org>
2 6
3 * processes.texi (Network Security): Made into its own section and 7 * processes.texi (Network Security): Made into its own section and
diff --git a/doc/lispref/text.texi b/doc/lispref/text.texi
index 7c88a5b25d1..2280a8e852a 100644
--- a/doc/lispref/text.texi
+++ b/doc/lispref/text.texi
@@ -4349,7 +4349,8 @@ document:
4349@end example 4349@end example
4350 4350
4351@noindent 4351@noindent
4352A call to @code{libxml-parse-html-region} returns this: 4352A call to @code{libxml-parse-html-region} returns this @acronym{DOM}
4353(document object model):
4353 4354
4354@example 4355@example
4355(html () 4356(html ()
@@ -4377,6 +4378,123 @@ that it parses the text as XML rather than HTML (so it is stricter
4377about syntax). 4378about syntax).
4378@end defun 4379@end defun
4379 4380
4381@menu
4382* Document Object Model:: Access, manipulate and search the @acronym{DOM}.
4383@end menu
4384
4385@node Document Object Model
4386@subsection Document Object Model
4387@cindex HTML DOM
4388@cindex XML DOM
4389@cindex DOM
4390@cindex Document Object Model
4391
4392The @acronym{DOM} returned by @code{libxml-parse-html-region} (and the
4393other @acronym{XML} parsing functions) is a tree structure where each
4394node has a node name (called a @dfn{tag}), and optional key/value
4395@dfn{attribute} list, and then a list of @dfn{child nodes}. The child
4396nodes are either strings or @acronym{DOM} objects.
4397
4398@example
4399(body
4400 ((width . "101"))
4401 (div
4402 ((class . "thing"))
4403 "Foo"
4404 (div
4405 nil
4406 "Yes")))
4407@end example
4408
4409@defun dom-node tag &optional attributes &rest children
4410This function creates a @acronym{DOM} node of type @var{tag}. If
4411given, @var{attributes} should be a key/value pair list.
4412If given, @var{children} should be @acronym{DOM} nodes.
4413@end defun
4414
4415The following functions can be used to work with this structure. Each
4416function takes a @acronym{DOM} node, or a list of nodes. In the
4417latter case, only the first node in the list is used.
4418
4419Simple accessors:
4420
4421@table @code
4422@item dom-tag @var{node}
4423Return the @dfn{tag} (also called ``node name'') of the node.
4424
4425@item dom-attr @var{node} @var{attributes}
4426Return the value of @var{attributes} in the node. A common usage
4427would be:
4428
4429@lisp
4430(dom-attr img 'href)
4431=> "http://fsf.org/logo.png"
4432@end lisp
4433
4434@item dom-children @var{node}
4435Return all the children of the node.
4436
4437@item dom-attributes @var{node}
4438Return the key/value pair list of attributes of the node.
4439
4440@item dom-text @var{node}
4441Return all the textual elements of the node as a concatenated string.
4442
4443@item dom-texts @var{node}
4444Return all the textual elements of the node, as well as the textual
4445elements of all the children of the node, recursively, as a
4446concatenated string. This function also takes an optional separator
4447to be inserted between the textual elements.
4448
4449@item dom-parent @var{dom} @var{node}
4450Return the parent of @var{node} in @var{dom}.
4451@end table
4452
4453The following are functions for altering the @acronym{DOM}.
4454
4455@table @code
4456@item dom-set-attribute @var{node} @var{attribute} @var{value}
4457Set the @var{attribute} of the node to @var{value}.
4458
4459@item dom-append-child @var{node} @var{child}
4460Append @var{child} as the last child of @var{node}.
4461
4462@item dom-add-child-before @var{node} @var{child} @var{before}
4463Add @var{child} to @var{node}'s child list before the @var{before}
4464node. If @var{before} is nil, make @var{child} the first child.
4465
4466@item dom-set-attributes @var{node} @var{attributes}
4467Replace all the attributes of the node with a new key/value list.
4468@end table
4469
4470The following are functions for searching for elements in the
4471@acronym{DOM}. They all return lists of matching nodes.
4472
4473@table @code
4474@item dom-by-tag @var{dom} @var{tag}
4475Return all nodes in @var{dom} that are of type @var{tag}. A typical
4476use would be:
4477
4478@lisp
4479(dom-by-tag dom 'td)
4480=> '((td ...) (td ...) (td ...))
4481@end lisp
4482
4483@item dom-by-class @var{dom} @var{match}
4484Return all nodes in @var{dom} that have class names that match
4485@var{match}, which is a regular expression.
4486
4487@item dom-by-style @var{dom} @var{style}
4488Return all nodes in @var{dom} that have styles that match @var{match},
4489which is a regular expression.
4490
4491@item dom-by-id @var{dom} @var{style}
4492Return all nodes in @var{dom} that have IDs that match @var{match},
4493which is a regular expression.
4494
4495@end table
4496
4497
4380@node Atomic Changes 4498@node Atomic Changes
4381@section Atomic Change Groups 4499@section Atomic Change Groups
4382@cindex atomic changes 4500@cindex atomic changes