Mozilla implements much of the DOM 3 XPath. This allows XPath expressions to be run against both HTML and XML documents.
var xpathResult = document.evaluate(xpathExpression, contextNode, namespaceResolver, resultType, result);
The evaluate function takes a total of five arguments:
- xpathExpression: A string containing an XPath expression to be evaluated.
- contextNode: A node in the document against which the XPath expression should be evaluated. The document node is the most commonly used.
- namespaceResolver: A function that will be passed any namespace prefixes from xpathExpression and return a string representing the namespace URI associated with that prefix. This enables conversion between the prefixes used in the XPath expressions and the (possibly different) prefixes used in the document. null is common for HTML documents or when no namespace prefixes are used.