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

Re: XPath and find/findAll methods

From: João Eiras <joaoe@opera.com>
Date: Tue, 22 Nov 2011 13:27:14 +0100
To: public-webapps@w3.org
Message-ID: <op.v5ckvot82q99of@joaoe>
On Tue, 22 Nov 2011 13:05:18 +0100, Simon Pieters <simonp@opera.com> wrote:

> On Mon, 21 Nov 2011 20:34:14 +0100, Martin Kadlec <bs-harou@myopera.com>  
> wrote:
>
>> Hello everyone,
>> I've noticed that the find/findAll methods are currently being  
>> discussed and there is one thing that might be a good idea to consider.
>>
>> Currently, it's quite uncomfortable to use XPath in javascript. The  
>> document.evalute method has lots of arguments and we have to remember  
>> plenty of constants to make it work. IE and Opera support selectNodes  
>> method on NodePrototype, which is really useful, but what's the point  
>> in using it when it doesn't work in FF/Chrome/Safari.
>
> Maybe FF/Chrome/Safari should add support for selectNodes?
>

The way IE has implemented selectNodes/selectSingleNode doesn't make it  
much XPath conformant, although their API is only available in XML  
documents created using a <xml> element or an ActiveXObject.

By default IE does a prefix match. If you call  
document.getProperty('SelectionLanguage') it returns 'XSLPattern'. You'd  
need to do document.setProperty('SelectionLanguage', 'xpath') to use real  
XPath and need you'd need to do  
document.setProperty('SelectionNamespaces', 'xmlns:a="foo" xmlns:b="bar"')  
to map the prefixes to a namespace.

Then the IE API looks like
  * Element.selectNodes/selectSingleNode(expression)
  * Document.selectNodes/selectSingleNode(expression, contextNode)

Opera has implemented the API with some clear differences.
  * obviously, the expression are always XPath
  * both Element and Document provide the contextNode
  * namespace resolver in the second argument. It is of the same kind as  
the one used in the DOM 3 XPath API

So it looks like
  * Element.selectNodes/selectSingleNode(expression, namespaceResolver)
  * Document.selectNodes/selectSingleNode(expression, namespaceResolver)

Neither Gecko nor Webkit have anything remotely related.

I think the API should steer in Opera's direction, with the remarks that  
the namespace resolver should be supported, and that the API should return  
other returns types than just Node, because XPath expressions can return  
strings and integers.
Received on Tuesday, 22 November 2011 12:27:46 GMT

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