XPathEvaluator
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Das XPathEvaluator
-Interface ermöglicht das Kompilieren und Auswerten von XPath-Ausdrücken.
Konstruktor
XPathEvaluator()
-
Erstellt ein neues
XPathEvaluator
-Objekt.
Instanzmethoden
XPathEvaluator.createExpression()
-
Erstellt einen geparsten XPath-Ausdruck mit aufgelösten Namespaces.
XPathEvaluator.createNSResolver()
Veraltet-
Gibt die Eingabe unverändert zurück.
XPathEvaluator.evaluate()
-
Bewertet einen XPath-Ausdrucksstring und gibt, wenn möglich, ein Ergebnis des angegebenen Typs zurück.
Beispiel
Zählen der Anzahl von <div>
-Elementen
Das folgende Beispiel zeigt die Verwendung des XPathEvaluator
-Interfaces.
HTML
<div>XPath example</div>
<div>Number of <div> elements: <output></output></div>
JavaScript
const xpath = "//div";
const evaluator = new XPathEvaluator();
const expression = evaluator.createExpression(xpath);
const result = expression.evaluate(
document,
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
);
document.querySelector("output").textContent = result.snapshotLength;
Ergebnis
Spezifikationen
Specification |
---|
DOM # interface-xpathevaluator |
Browser-Kompatibilität
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
XPathEvaluator | ||||||||||||
XPathEvaluator() constructor | ||||||||||||
createExpression | ||||||||||||
createNSResolver | ||||||||||||
evaluate |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- Deprecated. Not for use in new websites.