Re: ACTION-87: Selectors API

Daniel Schierbeck wrote:
> 
> Jim Ley wrote:
>>
>> "Daniel Schierbeck" <daniel.schierbeck@gmail.com>
>>>  var paragraphs = document.getElementsBySelector('xh|p', {xh: 
>>> 'http://www.w3.org/xhtml'});
>>
>> document.selectorsSelectElements(".chicken",{ 
>> lookupNamespaceURI=function(str) { return {egg:"urn:chicken", 
>> donkey:"urn:shiny"}[str] });
>>
>> Should do that...
>>
>> Jim. 
> I was hoping for something... um... simpler?

There are two problems with your 'hash' proposal. First of all it is
very javascript oriented. Your 'hash' is really just an object which you
access properties on, there is no way that would work in for example C++.

The other problem is that using js-objects as hashes has issues. For
example your hash would come pre-populated with some entries like
'toString', 'toSource' and 'watch'. You would also be unable to map the
prefixes '__parent__' and '__count__' to anything since those properties
are ReadOnly.

While these things aren't usually a problem since you're unlikly to use
those prefixes, it's not something I would want to bake into the standard.

So I suggest you just use a hash inside your XPathNSResolver function.
If you write clean code, rather then the one-liner above, it'll look
much simpler.

function resolver(str) {
   hash = {xh: 'http://www.w3.org/xhtml',
           xl: 'http://www.w3.org/1999/xlink'}
   return hash[str];
}
document.selectorsSelectElements('xh|p', resolver);


/ Jonas

Received on Tuesday, 28 February 2006 21:57:15 UTC