Next page Previous page Start of chapter End of chapter

Namespaces

Namespaces are implemented by attaching a prefix to each element and attribute. Each prefix is mapped to a URI by an xmlns:prefix attribute. The binding has scope within the element where the xmlns attribute is declared and within its content. Elements and attributes that are associated to the same URI belong to the same namespace. It is the URI that counts, not the prefix.

For instance, here is a solution for the element overloading problem described above. Notice that in the proposed solution the author of the CV is no more confused with the authors of the publications. The same for title and year.

When namespaces are only being used to identify the elements and attributes from a particular XML application, and not to distinguish different elements with the same name, default namespaces are better. Default namespaces can be used in two ways. By using an xmlns attribute without prefix and by declaring a fixed xmlns attribute in the DTD of the document. Some applications have their standard namespace URIs. For instance:

For instance, here is a solution for the application recognition problem described above.

Next page Previous page Start of chapter End of chapter
Caffè XML - Massimo Franceschet