This topic is intended to introduce and describe namespaces, their advantages and introduce them in 3B2. It is recommended that you have a basic understanding of XML before reading this topic.
Namespaces have been implemented in 3B2 with a view towards support for XML namespaces. XML is a syntax for marking up documents to be served and received in a variety of printed or electronic formats.
XML enables people to define their own elements (to create their own tags). This means that XML documents contain different and multiple markup vocabularies. Potentially, a name conflict could occur if documents use the same name to describe two different types of element. It is possible that elements clash or have different meanings in different circumstances. This can often cause difficulties of recognition and duplication between the elements, which in turn means that the XML can not be processed as desired.
For example, there could be two occurrences of the element <title> and four occurrences of the element <body> within the markup of an XML document all within different contexts or parent elements and all requiring different formatting. 3B2 could already deal with these publishing problems, but the use of namespaces standardises this practice.
A simple way to think of namespaces in 3B2 is as folders at the root of a drive in which you place and organise your elements, attributes etc.
Namespaces are used to uniquely identify and define the context of an element so that processing is easy. An XML document is made up of elements in a hierarchical tree structure. Every element has an element type name and a set of attributes. Namespaces define the hierarchy of elements in an XML document by attaching a desired prefix to each element.
The W3C namespace specification states that the namespace prefix should be a Uniform Resource Identifier (URI). The purpose of the URI is to give the namespace a unique name. Default URIs can also be provided for elements that don't have a prefix. Standard URIs identify elements from many XML applications. The namespace attribute is placed in the start tag of an element. A Uniform Resource Identifier (URI) is a short string that identifies resources on the Internet, for example, documents, images, downloadable files, services, electronic mailboxes and other resources. The most common URI is the Uniform Resource Locator (URL) which identifies an Internet domain address. In 3B2 namespace identifiers can take any format you choose, for example: <ns:element>
Namespaces enable processing software to recognise tags and attributes quickly and via a standard method. For example, some XML documents contain markup from multiple XML applications (an XML document may contain MathML markup) and namespaces enable you to differentiate between elements and attributes of the same name. Namespaces also make it possible to group all related elements and attributes from a single XML application together so that processing software can recognise them easily.
Namespaces provide the following advantages:
A 3B2 namespace is a named collection of various types of 3B2 tags. A namespace is a container for other tags. In 3B2, namespaces work along the same principle as directories or folders and share many of the same characteristics, such as:
In addition to the above:
Used in conjunction with 3B2, XML namespaces offer more control over XML documents by providing a simple method for qualifying element and attribute names used in XML documents by associating them with namespaces identifiers. This enables the use of elements of the same name to be formatted differently in XML documents.
You can find out more about namespaces by visiting:
The World Wide Web Consortium (W3C).
General and in-depth information about namespaces in XML:
See also