Most browsers today already have some form of support for XPath. However, the support for XPath varies between different browsers, and thus makes it difficult for developers to leverage this powerful technology. As a result, XPath support in browsers is largely under exploited today, in a way similar to how XMLHttpRequest object was not widely used just a few years ago.
XPath support in browsers:
- FireFox: Mozilla implements much of the DOM 3 XPath. It allows XPath expressions to be run against both HTML and XML documents;
- Internet Explorer: IE has XPath support built right into the Msxml.DOMDocument object. Each node has two methods that can be used to retrieve nodes matching an XPath pattern: selectNodes(), which returns a collection of nodes matching a pattern, and selectSingleNode(), which returns the first node that matches a given pattern. However, it does not apply to the general HTML document.
- Webkit: Starting from 3.0, Webkit has DOM XPath support built-in.
- Safari: it appears that Safari does not support XPath;
- Opera: Opera support XPath 1.0.
Why Is This Important?
XPath is a powerful approach for querying and processing document object models. It is a well understood standard. Most browsers already have some support for it. Further improvement on XPath support will make it easier for developers but also make web application perform better.
Another workaround is to use the various DOM query features that are available in various Ajax toolkits. This is an overlapping capabilities, but not one-for-one the same as XPath, and works against the HTML DOM, instead of against XML markup, and certainly lacks support for XML namespaces. Nevertheless, for some scenarios, this alternate approach is sufficient.
Background material that request this feature
- Why Are Ajax Applications Slow?
- [Various input documents to the Ajax runtime issue list draft Bertrand Le Roy]
- [Jon Ferraiolo Thoughts 20071001| Jon Ferraiolo]
Jon Ferraiolo's comments
I have positive and negative things to say about requesting XPath support:
- Negative: My only concern about promoting XPath support is the worry that if our list only consists of telling the browsers to implement standards faithfully, then that's not all that valuable of an exercise since they probably already know they need to implement standards faithfully.
Bertrand Le Roy's comments
This has become a lot less important since all new generation browsers implement CSS selector querying through querySelector.
Brad Neuberg's comments
I know there is sometimes a bias in the Ajax community against XML, but XML has its use-cases and can be great for certain things. XPath + XML is the way to go to quickly work with XML, grabbing just the pieces you want. Even better is being able to apply XPath on an HTML document, as you can on Firefox. CSS Selectors fall over when it comes to working with arbitrary XML; XPath gives you the control you need to just grab the pieces of an XML document you want. You might not even have IDs or classes in an arbitrary XML document, for example, so what do you do there with standard CSS selectors?
This proposal needs to clarify whether we are asking for better XPath 1 or XPath 2 support. XPath 1 is good enough, though XPath 2 adds some features that are occasionally useful.
Phase I Voting - Vote for Your Top 5 Features
NOTE: PHASE I VOTING IS NOW OPEN. (2008-04-01) We have now changed the voting procedure. Instead of putting votes on each separate wiki page, we are asking people to cast their Phase I Votes on the following wiki page:
Phase II Voting
More about this later.