Re: setting Node.prefix

Garret Wilson wrote:
> The documentation for Node.prefix says that Node.prefix will always be null
> if (for example) an element was created with DOM Level 1
> Document.createElement(). Yet there seems to be no restriction in setting
> the prefix (Node.setPrefix()) after the node is created.

If you use Document.createElement(tagName), the namespaceURI of your Element
node will be null:
[[[
Return Value 
 Element
  A new Element object with the nodeName attribute set to tagName, and
  localName, prefix, and namespaceURI set to null.
]]]

-- Document Object Model Core
http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-2141741547
Thu, 09 Nov 2000 23:18:19 GMT

Now, if you try to set the prefix with a null namespaceURI, you'll get
a DOMException.NAMESPACE_ERR:
[[[
NAMESPACE_ERR: Raised if the specified prefix is malformed, if the namespaceURI
of this node is null, [...]
]]]

-- Document Object Model Core
http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-NodeNSPrefix
Thu, 09 Nov 2000 23:18:19 GMT

There is no way to set the prefix on a DOM Level 1 node.

> 1. In all elements, does setting Node.nodeName update Node.prefix? (Why not?
> The converse is true, after all.)
> 2. In all elements, does setting Node.nodeName update Node.localName? (If #1
> is true, then this should be the case for consistency.)

Node.nodeName is read only. You can't set it.

> In other words, I would assume that, if the following takes place, the
> corresponding value changes will occur):
> 
> Step 1: Document document=myDocument.createElement("myNS:myElement")
> {nodeName="myNS:myElement"; prefix=null; localName=null;}

and namespaceURI=null;
 
> Step 2: myDocument.setPrefix("yourNS") {nodeNS="yourNS:myElement";
> prefix="yourNS"; localName="myElement"}

Step 2 raises a NAMESPACE_ERR DOMException.

Philippe

Received on Friday, 22 December 2000 10:29:42 UTC