W3C home > Mailing lists > Public > public-webapps@w3.org > October to December 2011

Re: XPath and find/findAll methods

From: Robin Berjon <robin@berjon.com>
Date: Thu, 24 Nov 2011 14:49:05 +0100
Cc: public-webapps WG <public-webapps@w3.org>
Message-Id: <C0FA6286-8267-42C3-8181-62B79472E7BE@berjon.com>
To: Jonas Sicking <jonas@sicking.cc>
On Nov 23, 2011, at 17:45 , Jonas Sicking wrote:
> On Wednesday, November 23, 2011, Robin Berjon <robin@berjon.com> wrote:
> > I would be thinking about something along the lines of (untested, off the top of my head):
> >
> > Node.prototype.queryXPath = function (xpath) {
> >    var snap = this.ownerDocument
> >                   .evaluate(xpath,
> >                             this,
> >                             function () { return "http://www.w3.org/1999/xhtml"; },
> >                             XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
> >                             null);
> >    var ret = [];
> >    for (var i = 0; i < snap.snapshotLength; i++) ret.push(snap.snapshotItem(i));
> >    return ret;
> > };
> >
> > Which hardly strikes me as a terribly complex addition.
> 
> I like this approach. Though I would make the type ANY and return whatever type the expression produced.

I agree that in general ANY_TYPE is desirable so that we can get non-node results, the problem is that for node sets it defaults (for reasons that defy any understanding that I have) to UNORDERED_NODE_ITERATOR_TYPE  when we clearly want something ordered and a snapshot. But specifying around that is not a big deal.

So, now for the money question: should we charter this?

-- 
Robin Berjon - http://berjon.com/ - @robinberjon
Received on Thursday, 24 November 2011 13:49:38 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 18:49:49 GMT