Quackit Logo
HTML
CSS
Scripting
Database
Hosting
Design
XML

Print Version

XML Local Namespace

In the previous lesson, we created a namespace to avoid a name conflict between the elements of two documents we wanted to combine. When we defined the namespace, we defined it against the root element. This meant that the namespace was to be used for the whole document, and we prefixed all child elements with the same namespace.

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

Example Local Namespace

Here, we apply the namespace against the title element only:

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

Multiple Namespaces

You could also have multiple namespaces within your XML document. For example, you could define one namespace against the root element, and another against a child element.

Example:

<bk:books xmlns:bk="http://somebooksite.com/book_spec">
  <bk:book>
    <bk:title>The Dream Saga</bk:title>
    <bk:author>Matthew Mason</bk:author>
    <pub:name xmlns:pub="http://somepublishingsite.com/spec">
      Sid Harta Publishers
    </pub:name>
    <pub:email>author@sidharta.com.au</pub:email>
  </bk:book>
  ...
</bk:books>

Enjoy this website?

  • Share
  • Add this page to your Favorites
  • Link to this page (copy/paste into your own website or blog):
  • Link to Quackit using one of these banner ads.
  • Help support Quackit by making a donation

Oh, and thank you for supporting Quackit!

© Copyright 2000 - 2010 Quackit.com