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

XPath and find/findAll methods

From: Martin Kadlec <bs-harou@myopera.com>
Date: Mon, 21 Nov 2011 20:34:14 +0100
Message-Id: <1321904054.28816.140661001844485@webmail.messagingengine.com>
To: public-webapps@w3.org
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.

My idea is to combine querySelector/All and selectNodes methods. This combination - find/findAll - would make using XPath much easier and it might give a good reason to lot's of programmers to use it instead of querySelector/All although it's going to be newer technology.

The problem is how to combine the methods, because in some cases it might not be clear if the string is xpath or css query. Because CSS queries are probably going to be used much more often than xpath it should be easier to call the method with CSS query. There is an idea I have but I would be glad for any other.

findAll(query, use_xpath):
CSS: findAll("nav a:first-child");
XPATH: findAll("//nav/a[1]", true);

Cheers,
Martin Kadlec
Received on Monday, 21 November 2011 22:12:27 GMT

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