A namespace is defined as a class of elements in which each element has a name unique to that class although it may be shared with elements of other classes. An analogy would be to see a namespace as a postal code, which clarifies which area the intended address is in despite it being possible to have multiple roads with the same name throughout a country. CSS does not currently describe a mechanism for resolving namespace prefixes, however namespaces can be declared using XML with a cascading style sheet. This requires that all namespaces should be declared on the document, ensuring they are all global and therefore there will be no collision of prefixes. In CSS, all namespaced elements must be referred to by their prefix. The major benefits of using namespaces include:
- Facilitate use of different XML vocabularies in the same XML document by resolving conflicts stemming from identical tags being used in different vocabularies. The name clashes need to be averted. The namespace qualifier makes the tag globally unique, thus obviating any ambiguities. It is not unusual to have multiple vocabularies in a single document; for example, XSLT stylesheet needs three different XML vocabularies so avoiding name clashes is of fundamental importance.
- Provides a simple, abbreviated, XML-compliant prefix for a unique uniform resource identifier (URI), thus avoiding syntactical difficulties stemming from non-compliant characters if one were forced to use full URI for qualifying tags.
- Improves readability – from a parser perspective short prefix is identical to full namespace name.
- Allows an organisation to have their distinct tags with distinct meanings through different namespaces associated with different URIs and they can all be called within same XML document., i.e. Adobe can have different tags for different image formats and they can all be used in a single document,
- Avoids tedium of typing by providing a mechanism for defining default namespace within a document so unqualified names automatically acquire this full qualification from parser perspective.
- To constrain a document to an XML vocabulary, we need XML Schema which can only be defined by using the reserved namespace http://www.w3.org/2001/XMLSchema which has all the attributes and elements of W3C XML schema specification. Also the document validators check document instance against the structures, elements, attributes, datatypes and constraints defined in associated XML schema. The link to associated schema in a document instance is through a namespace. Incidentally, we should appreciate that a namespace URI does not necessarily point towards anything on the implied location.
- Allows search engines to find similar documents with tags conforming to a namespace. In practice, namespace brings all the elements and attributes of a vocabulary together to be exploited by software.