XML News from Tuesday, May 30, 2006

The W3C Web API working group has posted the first public working draft of the Selectors API. "It is often desirable to perform script and or DOM operations on a specific set of elements in a document. [Selectors], mostly used in CSS [CSS21] context, provides a way of matching such a set of elements. This specification introduces two methods which take a selector (technically a group of selectors) as argument and return the matched elements as result." The spec offers the following JavaScript example:

function resolver(str) {
  var prefixes = {
    xh:  "http://www.w3.org/1999/xhtml",
    svg: "http://www.w3.org/2000/svg"}
  return prefixes[str];
}
var a = document.matchAll("xh|div > svg|svg", resolver);
var b = document.match("div.foo.bar");

I'm not sure why they've chosen the weak CSS syntax insetad fo the much more powerful and expressive XPath. Among other things, using XPath would allow colons to be used in qualified names instead of these weird vertical bars. Other things being equal, consiustency of syntax should be preferred. Perhaps it needs to handle malformed HTML?