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

I do not think @domenic meant removal of XML API

> Deprecate, and consider removing, XSLT
> 
> The consensus last time we considered this was that xml and xslt are too important for enterprise and we cannot remove them from the platform. Closing this bug to match that reality. We'll open a new bug if we ever decide to do this. [1] (Feb 22, 2019)

— https://bugs.chromium.org/p/chromium/issues/detail?id=514995


That said I have one example of XML API state. Have you known [DOMParser parsing text/xml is slower than text/html](https://bugzilla.mozilla.org/show_bug.cgi?id=1481080)?

We have `querySelector`/`querySelectorAll`, over the years it adopted many XPath selectors, yet there is no  `queryXPath`/`queryXPathAll` and its [polyfill is just a few lines](http://sergeykish.com/web-api-element-prototype-queryxpathall):

```
XPathResult.prototype[Symbol.iterator] = function *() {
  let next;
  while (next = this.iterateNext()) {
    yield next;
  }
}
Document.prototype.queryXPathAll = function(expression, ...args) {
  return [...this.evaluate(expression, this, args)]
}
Element.prototype.queryXPathAll = function(expression, ...args) {
  return [...this.ownerDocument.evaluate(expression, this, args)]
}
```

There was [a proposal](https://github.com/w3c/WebPlatformWG/issues/97), waits for #67, closed.

jQuery popularized CSS selectors. Somehow there is not much XPath, XPath 2.0, XPath 3.0 activity on the web. It would be great if its proponents described how it helps them. Personally I use XPath to query text nodes and as `:has` replacement

    //text()[last()]
    //a[text() = 'foo']
    //a[img]

I do not think Web developers know and use `count`, [etc](https://developer.mozilla.org/en-US/docs/Web/XPath/Functions). XPath 2.0 [extends it](https://www.w3.org/TR/xpath-functions-31/), feels a lot like [SQL](https://www.postgresql.org/docs/9.6/functions-datetime.html):

    //*[tokenize(@class, ' ') = 'foo']
    //time[fn:year-from-date(xs:date(@datetime)) = 2020]

I would prefer [Invisible XML](https://homepages.cwi.nl/~steven/ixml/) approach

    //*[id = 'foo']
    //p[class = 'bar']
    //p[lang/en/us]
    //date[datetime/year = '2020']
    //a[href/host = 'example.com']
    //span[xstyle/color = 'blue']

emulated with 

    <p><id>foo</id>id example</p>
    <p><class>bar</class></p>
    <p><lang><en><us></us></en></lang></p>
    <date><datetime><year>2020</year></datetime></date>
    <a><href><host>example.com</host></href></a>
    <span><xstyle><color>blue</color></style></span>

(`<style>` is CDATA, I use `<xstyle>` instead)

Each node node knows its type, parses underlying mini language and presents as if it was nodes.

-- 
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#issuecomment-709130959

Received on Thursday, 15 October 2020 10:35:53 UTC