- From: Ray David Whitmer <ray@jhax.net>
- Date: Mon, 06 Aug 2007 08:16:34 -0600
- To: Joćo Eiras <joao.eiras@gmail.com>
- Cc: www-dom@w3.org
Joćo Eiras wrote: > Hi all. > > Some ecmascript+dom implementations (aka, web browsers) allow this > statement to be executed > > node.setAttribute('xmlns','http://example.com/'); > > where node is an DOM Element. > What they do, I don't know, nor I expect for such behaviour to be > defined, since the specification > http://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-F68F082 > does not mention everything in this regard. > [...] Generally speaking, I believe an implementation which does not allow this is non-conforming. First of all, the function you are calling is not the version that must be called for namespace-aware applications. You should be calling node.setAttributeNS. Thus, you might be calling this on an XML application which does not conform to the namespaces specification, so why would it care? Secondly, even if you were calling setAttributeNS on a level 2 namespace-aware node, setting this value does NOT change the namespace of the element in question. A program which uses DOM for a namespace-aware application should not, in the first place, rely on xmlns attributes to determine the namespace of an element. That is the function of the corresponding DOM node functions that get the namespace URI. Setting xmlns through the API does not alter what is returned by those functions and does not change the namespace with which it will be serialized. When the document is serialized or normalized in a namespace-aware fashion the xmlns attributes may be preserved, where possible, but may be modified as required or as desired by the implementation to properly represent the actual namespace. Thus, the xmlns attributes might be said to contain no reliably-useful information within the DOM beyond a preferred set of namespace declarations, which will be modified as required, to represent the actual namespaces of the DOM nodes during serialization or normalization. Ray Whitmer
Received on Monday, 6 August 2007 14:16:43 UTC