Re: XPath and find/findAll methods

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 UTC