E4X and Namespaces

Oftentimes, XML documents will contain elements from a variety of namespaces. You can declare the default namespace for your E4X objects by placing the statement:

default xml namespace = "";

within the same scope as your E4X. You can also change namespaces at any time, by repeating the statement.

default xml namespace = "";
var a = <p>Some text</p>;
default xml namespace = "";
var b = <label>More text</label>;


<p xmlns="">
  Some text
  <label xmlns="">More text</label>


Using name() on an XML object returns a QName object (Qualified Name). QName is a global constructor available in JavaScript implementations supporting E4X. QName objects have two properties of particular relevance. The localName property returns the name of the element, without any namespace prefix. The uri property returns the uri of the namespace that the element is in.

var info =;
info.localName; // returns 'p'.
info.uri; // returns ""

Elements in no namespace return the empty string as their uri.

The Namespace global constructor is very similar to QName. Namespace differs in its toString method, and in that it has a prefix property instead of a localName property.

For further information on namespaces in E4X, see Processing XML with E4X.

Next is the global XML object.