What Is a Namespace, and Why Do You Need Them?

XML is useful for exchange of documents. A finite number of element type names is available to use to contain the document content. In a global Web, how do we handle the possibility of two element type names being the same? The solution that the W3C chose is namespaces.

Note

A namespace is a collection of names. In XML, a namespace refers to a collection of element type names and attribute names.

So, exactly why do we need namespaces? You might have document fragments such as the following:

<html> 
<head> 
<title>My XHTML document</title> 
</head> 
<body>Some content.</body> 
</html> 

and

 <persons> ...

Get Sams Teach Yourself XML in 10 Minutes 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.