What Is a Namespace?

To begin, every XML instance document has a namespace, whether it is explicitly named or not. So, in the current environment there is no escaping them. You can't run, you can't hide.

A namespace is nothing more than a set of names. Namespaces are themselves identified by a URI, which I'll discuss next. But first let's drill in the concept with an analogy.

Consider a youth soccer league family picnic. The set of everyone attending the picnic forms our universe, or the default, unnamed namespace. Consider two people named Bob who are attending the picnic with their sons and daughters (Figure 4.1).

Figure 4.1. Two Bobs at the Picnic


Suppose that the coach calls out for Bob to help cook the hot dogs. Unless the coach is looking directly at one or the other of them, how are they to know which one should answer? Maybe they're both perfectly happy sitting in their lawn chairs, nursing brewskis, and they both ignore him. The coach gets annoyed because he also needs to get someone else started setting up some more tables. So, he calls out, “Bob Smith!” He has just used a namespace. Figure 4.2 shows the two Bobs “disambiguated” by putting them in the namespaces of the Smith and Jones surnames.

Figure 4.2. The Smith and Jones Namespaces


In a nutshell, that's all there is to namespaces. Now, there are certainly complexities in how they are used and how they are resolved, but that's the basic concept. For most things you'll have to deal with, you need to grasp only this essential concept and a few more details.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset