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 ...
Get Beginning XML, 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.