W3C home > Mailing lists > Public > public-webapps@w3.org > July to September 2008

Re: [selectors-api] Investigating NSResolver Alternatives

From: Lachlan Hunt <lachlan.hunt@lachy.id.au>
Date: Sun, 13 Jul 2008 09:56:43 +0200
Message-ID: <4879B53B.1050703@lachy.id.au>
To: Boris Zbarsky <bzbarsky@MIT.EDU>
Cc: public-webapps <public-webapps@w3.org>

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 

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

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
* 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 

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

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
Received on Sunday, 13 July 2008 07:57:25 UTC

This archive was generated by hypermail 2.3.1 : Friday, 27 October 2017 07:26:11 UTC