XML Default Namespace

This article provides a brief overview of default namespaces.

The namespaces we created in the previous two lessons involved applying a prefix. We applied the prefix when we defined the namespace, and we applied a prefix to each element that referred to the namespace.

You can also use what is known as a default namespace within your XML documents. The only difference between a default namespace and the namespaces we covered in the previous two lessons is, a default namespace is one where you don't apply a prefix.

You can also define namespaces against a child node. This way, you could use multiple namespaces within the same document if required.

Example Default Namespace

Here, we define the namespace without a prefix:

When you define the namespace without a prefix, all descendant elements are assumed to belong to that namespace, unless specified otherwise (i.e. with a local namespace).

Real Life Example

When writing XHTML documents, authors usually define http://www.w3.org/1999/xhtml as the default namespace. Doing this enables authors to use the XHTML tags without a prefix.