Re: [selectors-api] Investigating NSResolver Alternatives

Boris Zbarsky wrote:
> Lachlan Hunt wrote:
>> * Defining a new native object that can have namespace declarations
>>   added to it by scripts.
>>
>>   var resolver = new NamespaceResolver()
>>   resolver.add("prefix", "uri");
>>
>> pro: Easy for authors to use
>> pro: Relatively easy for implementers to implement
>> con: Requires me to specify a new interface
> 
> Offhand, this sounds like the simplest approach to me if we do decide to 
> change things around at this late date.

If this alternative would be preferred over the proposed @namespace 
solution, I have written a rough proposal for how this could work.

Constructor] interface NamespaceMapper {
   void set([Null=Empty] in DOMString prefix, [Null=Null] in DOMString 
namespace);
};

(Note: undefined is not treated specially here, it just stringifies to 
"undefined")

Authors must construct and pass a NamespaceMapper object as the 
nsresolver.  To specify a namespace, authors invoke the set method, 
passing the prefix and associated namespace URI.  To store the default 
namespace, authors must set the prefix to an empty string.

(There is no way to remove a namespace, but setting the value to null 
will have the same effect.)

Objects implementing the Window interface must provide an 
NamespaceMapper() constructor.  When the object is constructed, the 
implementation must create a lookup table for storing and retrieving 
namespace prefixes and URIs, which is indexed by the prefix.

When the set method is invoked, the implementation must perform the 
following algorithm

* Convert the prefix into canonical form using the Unicode case folding
   algorithm
* Let key be the canonical form of the prefix
* Let value be the namespace URI
* If key already exists within the lookup table, replace its associated 
value with value
* Otherwise, store the key and value in the lookup table


To resolve namespaces, the implementation must perform the following 
algorithm:

If there is no resolver
* There is no default namespace
* If there are prefixes that need to be resolved, raise a NAMESPACE_ERR
   exception

Otherwise, a resolver was passed
* If it's not a NamespaceMapper object, raise a TYPE_MISMATCH_ERR
* Otherwise, to obtain the default namespace, perform a lookup using the
   empty string as the key.
   - If a value is found and it is not null or an empty string, use that
     as the default namespace
   - Otherwise, there is no default namespace
* To resolve a prefix, implementations must convert the prefix into
   canonical form using the Unicode case folding algorithm and perform a
   lookup using this value
   - If a value is found and it is not null or an empty string, use this
     as the namespace URI
   - If the value was null or not found, raise a NAMESPACE_ERR exception

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

Received on Sunday, 13 July 2008 07:57:25 UTC