XML namespaces are simple in concept but difficult to explain because they can be declared and used in many different ways. In this article, I explain XML namespaces in their most basic form. Let's start with a basic XML document used to store air travel reservations.
Welcome to Bucaro TecHelp!

Welcome to Bucaro TecHelp!
Maintain Your Computer and Use it More Effectively
to Design a Web Site and Make Money on the Web

[About BTH]  [User Agreement]  [Privacy Policy]  [Site Map]  [Contact Form]  [Advertise on BTH]  [News Feed]

Google
Web
This Site
   WARNING!
What you learn from these Totally FREE
Einstein Newsletters could cause your friends to mistake you for someone else!
  [] automobiles
  [] business
  [] parenting
  [] computers
  [] contests
  [] education
  [] entertainment
  [] food/wine
  [] free stuff
  [] genealogy
  [] health/fitness
  [] home/garden
  [] humor
  [] marketing
  [] investing
  [] pets
  [] inspiration
  [] self-improve
  [] recreation
  [] travel
  [] womens stuff
  [] writing/reading
Click here and choose as many as you like!

XML Namespaces Explained

The XML document, shown below, contains a top-level node, identified by the <reservations> tag, which contains several <trip> child nodes.

<reservations>
  <trip>
    <origin>Chicago</origin>
    <destination>Phoenix</destination>
    <seat>d4</seat>  
    <name>Jim Shoe</name>
    <date>06/05/05</date>
  </trip>
  <trip>
    <origin>Boston</origin>
    <destination>Miami</destination>
    <seat>c1</seat>  
    <name>Bob Sled</name>
    <date>06/05/05</date>
  </trip>
</reservations>

The names within the tags in this XML document are referred to as it's "vocabulary". If this was the only XML document we needed to deal with, namespaces would be unnecessary. In fact version 1.0 of the XML specification did not contain namespaces. But let's consider the The XML document shown below which is used to store rental car reservations.

<reservations>
  <trip>
    <make>Chevrolet Cavalier</make>
    <origin>Chicago</origin>
    <destination>Phoenix</destination>
    <name>Jim Shoe</name>
    <date>06/06/05</date>
  </trip>
  <trip>
    <make>Dodge Caravan</make>
    <origin>Miami</origin>
    <destination>Chciago</destination>
    <name>Bob Sled</name>
    <date>06/06/05</date>
  </trip>
</reservations>

This XML document also contains a top-level node, identified by the <reservation> tag. In fact this document uses almost the same vocabulary as the XML document used to store air travel reservations. What happens if we combine both XML documents in a application that displays all reservations.

We can't distinguish, for example an air travel reservations <reservations><trip><origin> from a rental car reservations <reservations><trip><origin>. We need some way to distinguish air travel reservations from rental car reservations. The solution is to identify the air travel reservations with a prefix, as shown below.

<air:reservations>
  <trip>
    <origin>Chicago</origin>
    <destination>Phoenix</destination>
    <seat>d4</seat>  
    <name>Jim Shoe</name>
    <date>06/05/05</date>
  </trip>
  <trip>
    <origin>Boston</origin>
    <destination>Miami</destination>
    <seat>c1</seat>  
    <name>Bob Sled</name>
    <date>06/05/05</date>
  </trip>
</air:reservations>

Programming Sections
XML

[Site User Agreement]  [Advertise on This site]  [Search This Site]  [Contact Form]
Copyright©2001-2007 Bucaro TecHelp P.O.Box 18952 Fountain Hills, AZ 85269