What is a Namespace?
  • 21 Oct 2021
  • 4 Minutes to read
  • Contributors
  • Dark
    Light

What is a Namespace?

  • Dark
    Light

A namespace is a set of characters used to arrange objects of different kinds so that they may be designated by name.

Key examples include:

  • File systems are namespaces that give names to files.
  • Some programming languages arrange their subroutines and variables in namespaces.
  • Distributed systems and computer networks give names to resources such as printers, computers, websites, remote files and so on.

Generally, a namespace is used to uniquely identify a set of names to avoid ambiguity when objects with different origins but identical names are lumped together. With the Extensible Markup Language (XML), an XML namespace is a group of attribute names and element types. These attribute names and various elements types are identified uniquely by the name of the unique XML namespace which they from a part of.

In an XML document, any attribute name or element type can therefore have a two-part name comprising of its functional name and the name of its namespace. For instance, say the same XML document included the element type of SELLER for sellers of scooters and sellers of power bikes. Having different scooters and power bike namespaces would make this easy. Essentially, it would make it possible to label scooter owners differently from power bike owners without needing to open a different element type for both sets of characters.

In XML, a namespace is normally assigned the name of a Uniform Resource Identifier (URI), like a web site’s address for two reasons;

  • Because the namespace may be linked with the site of page of that URI (for example a business name)
  • And because the URI is more likely to be a unique name.

The URI is not supposed to be used for any other function other than as a name, neither is there any XML schema or namespace document that must retrieved. The sole function of the URI is simply as a name- and part of the two-part name of any attribute name or element type so that the names remain unique in the file.

Name conflicts

Developers specify the element names. This often leads to a conflict when trying to combine XML documents from various XML applications. If the XML fragments of two characters like “timetable” and “coffee table” were merged together, there would be a conflict because both characters contain a

element, even though they have different meanings and content. An XML parser will find it difficult handling these differences.

Solution through prefix

Name conflicts in XML can be avoided easily by means of a name prefix. This XML distinguishes between data about the “timetable” and “coffee table” by prefixing “t” and “c” at the start xml/xml_namespaces.asp

Naming system

A name in a namespace is made up of a namespace identifier and a local name. The namespace name is often used as the prefix to the local name.

In the form of an augmented Backus-Naur:

Name = separator

When local names are used on their own, a name resolution is implemented to determine which (if at all any) specific item is referred to by a particular local name.

Namespace Delegation

Delegating responsibilities between various characters in real-world applications is critical, for example, in the World Wide Web (WWW). Namespaces make it possible to delegate identifier assignments to several names using organisations, while maintaining the global uniqueness. The assigned namespace identifiers are registered by a central registration authority.

Every namespace identifier is given to an organisation which is consequently responsible for the allocation of names in their designated namespaces. This organisation may be responsible for issuing names, and gives the names themselves, or another Registration authority that further assigns parts of their namespace to various organisations.

Namespace Hierarchy

A hierarchical namespace is a naming scheme that allows namespaces to be sub-delegated to third parties. A hierarchy is said to be recursive if its syntax for namespace identifiers is identical for each sub-delegation. A perfect example of a hierarchy that is recursive is the Domain Name System. A Uniform resource name representing IANA number is an example of a non-recursive hierarchy.

Namespace versus scope

A namespace identifier gives context (or scope) to a name, and sometimes, the terms may be interchangeable. However, other factors may also be responsible for providing the name contexts, such as the syntax of the name syntax or the location it occurs.

In programming languages

Namespace is a context for the identifiers of many programming languages. In an operating system, a directory is an ideal example of a namespace. A context may also be called a namespace because identical names in different namespaces can have different connotations, with each one applicable to its namespace.

Some attributes of namespaces

Names in the namespaces can represent concepts as well as objects, whether the namespace is an ethnic or a natural language. In Java, identifiers that occur in namespaces have a long unique “qualified” name and a short local name for other uses outside the namespace. Compliers such a C++ combine names for internal use and namespaces in a compiler process known as name mangling.


Was this article helpful?

What's Next