Node.namespaceURI

  • Revision slug: DOM/Node.namespaceURI
  • Revision title: Node.namespaceURI
  • Revision id: 131118
  • Created:
  • Creator: Hsivonen
  • Is current revision? No
  • Comment Document changes from bug 468708; 58 words added, 23 words removed

Revision Content

{{ DomRef() }}

Summary

The namespace URI of the node, or null if it is unspecified (read-only). When the node is a document, it returns the XML namespace for the current document.

Syntax

namespace = node.namespaceURI 
  • namespace is a string that represents the namespace URI of the specified node.

Example

In this snippet, a node is being examined for its localName and its namespaceURI. If the namespaceURI returns the XUL namespace and the localName returns "browser", then the node is understood to be a XUL <browser/>.

if (node.localName == "browser" && 
    node.namespaceURI == "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul") {
  // this is a XUL browser 
}

Notes

This is not a computed value that is the result of a namespace lookup based on an examination of the namespace declarations in scope. The namespace URI of a node is frozen at the node creation time.

In Firefox 3.5 and earlier, the namespace URI for HTML elements in HTML documents is null. In later versions, in compliance with HTML5, it is http://www.w3.org/1999/xhtml as in XHTML. {{ gecko_minversion_inline("1.9.2") }}

For nodes of any nodeType other than ELEMENT_NODE and ATTRIBUTE_NODE the value of namespaceURI is always null.

You can create an element with the specified namespaceURI using the DOM Level 2 method document.createElementNS.

Per the Namespaces in XML specification, an attribute does not inherit its namespace from the element it is attached to. If an attribute is not explicitly given a namespace, it has no namespace.

The DOM does not handle or enforce namespace validation per se. It is up to the DOM application to do any validation necessary. Note too that the namespace prefix, once it is associated with a particular node, cannot be changed.

Specification

DOM Level 2 Core: namespaceURI

DOM Level 2 Core: XML Namespaces

{{ languages( { "fr": "fr/DOM/element.namespaceURI", "ja": "ja/DOM/element.namespaceURI", "pl": "pl/DOM/element.namespaceURI" } ) }}

Revision Source

<p>{{ DomRef() }}</p>
<h3 name="Summary">Summary</h3>
<p>The namespace URI of the node, or <code>null</code> if it is unspecified (read-only). When the node is a document, it returns the XML namespace for the current document.</p>
<h3 name="Syntax">Syntax</h3>
<pre class="eval"><em>namespace</em> = <em>node</em>.namespaceURI 
</pre>
<ul> <li><code>namespace</code> is a string that represents the namespace URI of the specified node.</li>
</ul>
<h3 name="Example">Example</h3>
<p>In this snippet, a node is being examined for its <a href="/En/DOM/Node.localName" title="En/DOM/Node.localName">localName</a> and its <code>namespaceURI</code>. If the <code>namespaceURI</code> returns the XUL namespace and the <code>localName</code> returns "browser", then the node is understood to be a XUL <code>&lt;browser/&gt;</code>.</p>
<pre>if (node.localName == "browser" &amp;&amp; 
    node.namespaceURI == "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul") {
  // this is a XUL browser 
}
</pre>
<h3 name="Notes">Notes</h3>
<p>This is not a computed value that is the result of a namespace lookup based on an examination of the namespace declarations in scope. The namespace URI of a node is frozen at the node creation time.</p>
<p>In Firefox 3.5 and earlier, the namespace URI for HTML elements in HTML documents is <code>null</code>. In later versions, in compliance with HTML5, it is <code><a class=" external" href="http://www.w3.org/1999/xhtml" rel="freelink">http://www.w3.org/1999/xhtml</a></code> as in XHTML. {{ gecko_minversion_inline("1.9.2") }}</p>
<p>For nodes of any <a href="/En/DOM/Node.nodeType" title="En/DOM/Node/NodeType/Node.nodeType">nodeType</a> other than <code>ELEMENT_NODE</code> and <code>ATTRIBUTE_NODE</code> the value of <code>namespaceURI</code> is always <code>null</code>.</p>
<p>You can create an element with the specified <code>namespaceURI</code> using the DOM Level 2 method <a href="/en/DOM/document.createElementNS" title="en/DOM/document.createElementNS">document.createElementNS</a>.</p>
<p>Per the <a class="external" href="http://www.w3.org/TR/xml-names11/">Namespaces in XML</a> specification, an attribute does not inherit its namespace from the element it is attached to. If an attribute is not explicitly given a namespace, it has no namespace.</p>
<p>The DOM does not handle or enforce namespace validation per se. It is up to the DOM application to do any validation necessary. Note too that the namespace prefix, once it is associated with a particular node, cannot be changed.</p>
<h3 name="Specification">Specification</h3>
<p><a class="external" href="http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-NodeNSname">DOM Level 2 Core: namespaceURI</a></p>
<p><a class="external" href="http://www.w3.org/TR/DOM-Level-2-Core/core.html#Namespaces-Considerations">DOM Level 2 Core: XML Namespaces</a></p>
<p>{{ languages( { "fr": "fr/DOM/element.namespaceURI", "ja": "ja/DOM/element.namespaceURI", "pl": "pl/DOM/element.namespaceURI" } ) }}</p>
Revert to this revision