Re: [selectors-api] Proposal to Drop NSResolver from Selectors API v1

Maciej Stachowiak wrote:
> On May 12, 2008, at 9:38 AM, Bjoern Hoehrmann wrote:
>> (There are other problems with using an object like the one you propose,
>> like being unable to specify a default namespace, unless you introduce
>> some kind of magic prefix representing the default namespace; ultimately
>> you don't gain much; you could also just accept a simple string in the
>> form "prefix1=ns1 prefix2=ns2 ..." like MSXML does for XPath, but there
>> isn't really a problem worth solving with the resolver function.)
> 
> I'm convinced. I like the string better than my proposal. It removes the 
> need to specify anything regarding setters or other language bindings.

If I were to define that such a string should be used instead, would the 
following processing requirements work?

var ns = "http://www.w3.org/1999/xhtml svg=http://www.w3.org/2000/svg"
.querySelector("p svg|svg", ns);


Let ns be an empty hash map, where the key is the prefix and the value 
is the namespace uri.
Tokenise the nsresolver string by splitting on whitespace.
For each token:
   If there is an '=' character in the string:
     Split the string on the first '=' character
     Let prefix be the string before the '=' character
     Let uri be the string after the '=' character

   Otherwise, there is no '=' character:
     Let prefix be "" (the default namespace)
     Let uri be value of this token

   If ns[prefix] does not already exist:
     Let ns[prefix] = uri

-- 
Lachlan Hunt - Opera Software
http://lachy.id.au/
http://www.opera.com/

Received on Monday, 12 May 2008 18:01:29 UTC