Home arrow XML arrow Page 2 - Doing More With XML Schemas (part 4)

Stocking Up - XML

In this concluding article, find out all about namespaces - what they are, how they work, and how you can use schemas to make sure that they're enforced in a consistent manner.

  1. Doing More With XML Schemas (part 4)
  2. Stocking Up
  3. The Name Game
  4. Setting Policy
  5. Old Friends And New
  6. Being Selective
  7. Closing Time
By: Harish Kamath, (c) Melonfire
Rating: starstarstarstarstar / 7
February 12, 2003

print this article


First, the basics. A namespace is simply a prefix added to an element in order to distinguish it from other elements with the same name.

An example might help to make this clearer. Let's suppose that I decided to encode my stock portfolio as an XML document. Here's what it might look like:

<?xml version="1.0"?> <portfolio> <stock>Cisco Systems</stock> <stock>Nortel Networks</stock> <stock>eToys</stock> <stock>IBM</stock> </portfolio>

And now let's suppose that Tom, my next-door neighbour and the proud owner of his own computer store, hears about XML, gets really excited, and assigns some of his employees to the task of encoding his store's inventory into XML. Here's what his XML document might look like:

<?xml version="1.0"?> <inventory> <item name="Mouse C106"> <vendor>Logitech</ vendor> <stock>100</stock> </item> <item name="Visor Deluxe"> <vendor>HandSpring</vendor> <stock>23</stock> </item> <item name="Nomad"> <vendor>Creative</vendor> <stock>2</stock> </item> </inventory>

Finally, let's suppose that Tom and I get together for a drink, tell each other about our XML experiments and (in a moment of tequila-induced clarity) decide to put XML's capabilities to the test by combining our two documents into one. However, since both documents include a tag named


whose meaning is entirely dependent on its context, it's pretty obvious that our attempt at integration will fail, since an XML application would have no way of telling whether the data enclosed between <stock>...</stock> tags belonged to my portfolio or Tom's inventory.

It's precisely to avoid this kind of ambiguity that the XML specification now provides for namespaces. Namespaces are a way to uniquely identify specific elements within an XML document. This is accomplished by assigning a unique prefix to an element, thereby immediately associating it with a particular data universe and eliminating ambiguity.

>>> More XML Articles          >>> More By Harish Kamath, (c) Melonfire

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Google Docs and Xpath Data Functions
- Flex Array Collection Sort and Filtering
- The Flex Tree Control
- Flex List Controls
- Working with Flex and Datagrids
- How to Set Up Podcasting and Vodcasting
- Creating an RSS Reader Application
- Building an RSS File
- An Introduction to XUL Part 6
- An Introduction to XUL Part 5
- An Introduction to XUL Part 4
- An Introduction to XUL Part 3
- An Introduction to XUL Part 2
- An Introduction to XUL Part 1
- XML Matters: Practical XML Data Design and M...

Developer Shed Affiliates


Dev Shed Tutorial Topics: