- From: Maciej Stachowiak <mjs@apple.com>
- Date: Mon, 12 May 2008 07:13:08 -0700
- To: Bjoern Hoehrmann <derhoermi@gmx.net>
- Cc: public-webapi <public-webapi@w3.org>
On May 12, 2008, at 5:52 AM, Bjoern Hoehrmann wrote: > * Maciej Stachowiak wrote: >> A function is not a particularly convenient way to specify a >> namespace >> mapping, and it creates these error handling issues as well as >> causing >> problems with case (in)sensitivity. Even though NSResolver is what >> XPath uses, wouldn't it be simpler to just accept an object that >> provides the relevant namespace mappings? > > That would preclude simple solutions to the resolution problem like > http://lists.w3.org/Archives/Public/public-webapi/2008Apr/0204.html > >> I originally thought that >this could be a JSON-style JavaScript >> object, >> but it seems to me that a DOM node would actually work just as well. >> Most of the time, you want to use the namespace prefixes in effect >> for >> the root element, and if not, then it is pretty simple to construct a >> DOM node with all the right xmlns declarations. > > That would not have the particular problem above, but many others. > I do not think you want the prefixes on the document element most > of the time, it is not as easy to create such a node as you suggest, > and all in all this would likely cause great confusion. It's hard > to imagine the typical user of this API using code like this: > > var node = document.createElementNS(null, "magic-ns-element"); > node.setAttributeNS('http://www.w3.org/2000/xmlns/', > 'xmlns:xht', 'http://www.w3.org/1999/xhtml'); > node.setAttributeNS('http://www.w3.org/2000/xmlns/', > 'xmlns:svg', 'http://www.w3.org/2000/svg'); > node.setAttributeNS('http://www.w3.org/2000/xmlns/', > 'xmlns:mml', 'http://www.w3.org/1998/Math/MathML'); > > I think this would be a very bad idea. This does not look much better (it does avoid repeatedly mentioning the xmlns namespace at least): function resolver(prefix) { if (prefix == "xht") { return "http://www.w3.org/1999/xhtml"; } else if if (prefix == "svg") { return "http://www.w3.org/2000/svg"; } else if (prefix == "mml") { return "http://www.w3.org/2000/xmlns/"; } return null; // ??? } However, this does look better: var namespaces = {xht: "http://www.w3.org/1999/xhtml"; svg: "http://www.w3.org/2000/svg "; mml: "http://www.w3.org/1998/Math/MathML" }; I therefore make a second proposal to accept either vanilla JS objects of this format or DOM nodes, instead of NSResolver objects. Regards, Maciej
Received on Monday, 12 May 2008 14:13:54 UTC