XPATH SUPPORT IN BROWSERS
XPath was created as a way to locate specific nodes within a DOM document, so it's important to XML processing. An API for XPath wasn't part of a specification until DOM Level 3, which introduced the DOM Level 3 XPath recommendation. Many browsers chose to implement this specification, but Internet Explorer decided to implement support in its own way.
DOM Level 3 XPath
The DOM Level 3 XPath specification defines interfaces to use for evaluating XPath expressions in the DOM. To determine if the browser supports DOM Level 3 XPath, use the following JavaScript code:
let supportsXPath = document.implementation.hasFeature("XPath", "3.0");
Although there are several types defined in the specification, the two most important ones are XPathEvaluator
and XPathResult
. The XPathEvaluator
is used to evaluate XPath expressions within a specific context. This type has the following three methods:
createExpression(
expression, nsresolver
)
&...