Cover by Joe Fawcett, Liam R.E. Quin, Danny Ayers

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

O'Reilly logo

Chapter 3

XML Namespaces

WHAT YOU WILL LEARN IN THIS CHAPTER:

  • What namespaces are
  • Why you need namespaces
  • How to choose a namespace
  • How to declare a namespace
  • How to show that items are in a namespace
  • The relationship between namespaces and XML Schema
  • When to use namespaces
  • Common uses of namespaces

This chapter covers the thorny topic of XML Namespaces, something that should be quite simple and straightforward but often seems to lead to confusion, even among experienced developers. This chapter starts by explaining what is meant by the term namespace and how it’s not limited to the world of XML. It then details when and why you would need them and shows the problems you can experience if they were not available. Then you delve into the implementation of namespaces, how they are declared in an XML document, and how you specify that an item resides in a particular namespace. You are then introduced to one of the main uses of namespaces, XML Schemas, which enable you to validate that a particular document conforms to a pre-determined structure. The final section lists some real-world examples of namespace usage that you are likely to encounter and gives a brief description of where and why they are used.

DEFINING NAMESPACES

At their simplest, namespaces are a way of grouping elements and attributes under a common heading in order to differentiate them from similarly-named items.

Take the following scenario: You overhear two people talking and one says to the other, “You need a ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required