Difference between revisions of "XPath"

From GreaseSpot Wiki
Jump to navigationJump to search
m
(→‎More information: Added link to XPath tutorial.)
Line 16: Line 16:


* [http://developer.mozilla.org/en/docs/Introduction_to_using_XPath_in_JavaScript Mozilla Developer Center: Introduction to using XPath in JavaScript]
* [http://developer.mozilla.org/en/docs/Introduction_to_using_XPath_in_JavaScript Mozilla Developer Center: Introduction to using XPath in JavaScript]
* [http://www.zvon.org/xxl/XPathTutorial/General/examples.html XPath tutorial]
* [http://en.wikipedia.org/wiki/XPath Wikipedia: XPath]
* [http://en.wikipedia.org/wiki/XPath Wikipedia: XPath]


{{stub}}
{{stub}}

Revision as of 18:19, 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. See the links below for documentation of the XPath language.

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.

More information