XPath: Difference between revisions
→More information: Added links to MDC on axes and functions. |
mNo edit summary |
||
Line 3: | Line 3: | ||
XPath is very fast compared to manual DOM traversal (see e.g. [http://ejohn.org/blog/getelementsbyclassname-speed-comparison/ getElementsByClassName Speed Comparison]). | XPath is very fast compared to manual DOM traversal (see e.g. [http://ejohn.org/blog/getelementsbyclassname-speed-comparison/ getElementsByClassName Speed Comparison]). | ||
This page is intended for tips and gotchas related to using XPath in Greasemonkey scripts. See the links below for | This page is intended for tips and gotchas related to using XPath in Greasemonkey scripts, not complete documentation. See the links below for that. | ||
== Using XPath in Greasemonkey == | == Using XPath in Greasemonkey == |
Revision as of 22:30, 22 May 2007
XPath (XML Path Language) is a language for addressing elements in a XML or HTML document. XPath expressions describe paths in a tree represention of the document.
XPath is very fast compared to manual DOM traversal (see e.g. getElementsByClassName Speed Comparison).
This page is intended for tips and gotchas related to using XPath in Greasemonkey scripts, not complete documentation. See the links below for that.
Using XPath in Greasemonkey
The most convenient way to use XPath in Greasemonkey scripts is with a helper function. The insides of that function illustrate the less convenient way.
Relative paths
Note that relative XPath expressions, that start from some specific node, do not begin with a /
. Start them with a period, e.g. .//a
, or an axis, e.g. descendant::a
. The default axis is child
, so just a
works to find an immediate descendant.