Quackit Logo

XML Default Namespace

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:

<books xmlns="http://somebooksite.com/book_spec">
  <book>
    <title>The Dream Saga</title>
    <author>Matthew Mason</author>
  </book>
  ...
</books>

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.

Enjoy this website?

  1. Link to this page (copy/paste into your own website or blog):
  2. Add this page to your favorite social bookmarks sites:
                     
  3. Add this page to your Favorites

Oh, and thank you for supporting Quackit!