[whatwg/dom] Proposal - Update XPath to (at least) v2.0 (#903)

While the latest recommendation is [v3.1](https://www.w3.org/TR/xpath-31/), most questions related to XPath seems to miss *Regular Expressions*, introduced in [v2.0](https://www.w3.org/TR/xpath20/) which is nearly a 10 years ago recommendation.

However, all browsers support only [XPath v1.0 from 1999](https://www.w3.org/TR/1999/REC-xpath-19991116/).

## Background

Widely [adopted in 2007 by popular frameworks](https://johnresig.com/blog/xpath-overnight/) such as Dojo, Prototype, or Mootools, the *XPath* language is an extremely powerful tool to query and crawl the DOM in all its axes, hence superior than CSS, and able to unleash proposed selectors already, such as `:has(...)` even in its version 1.

```js
// CSS container:has(child)
// XPath since 1999
'.//container[count(.//child) > 0]'
```

But this is only scratching the surface of operations that XPath can do, as opposite of querying via CSS, check surrounding DOM nodes via JS, check results are valid (i.e. `if (child.closest('container'))` plus there's no way to target text nodes or even comments.

## Proposal

Provide at least the method `matches(RegExp, flag)` to the current XPath 1.0 (let's call it 1.1) *or* provide at least v.2 of this old but gold standard to crawl any DOM tree, as if it's still updated and useful for back end crawlers, it's unclear why the first class citizen JS should not benefit from its potentials, way superior than CSS selectors, and less error prone, as filtering and complex searches can be done directly through `document.evaluate`.

Thanks in advance for considering this improvement, as I'm sure once RegExp will be in, the usage of XPath for complex SPA/PWA pages would flourish again in either libraries, web components, or the Web in general.


-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/903

Received on Tuesday, 13 October 2020 11:15:44 UTC