ITWissen.info - Tech know how online

namespace XML

Namespaces are a simple method of uniquely naming element names and attribute names in XML documents. The element and attribute names are linked in such a way that they can be uniquely identified by URI references. In this respect, the URI reference is merely an unambiguous identifier; unlike a reference to a Document Type Definition( DTD) or an XML schema, the XML processor or parser does not search for a list of names specifically stored there.

The namespace method was first introduced by the World Wide Web Consortium(W3C) in 1999 in the recommendation "Namespaces in XML". A German translation of this recommendation is available under the link below. The background of the agreement of namespaces is to unambiguously reference the information units in XML documents and thus to avoid possible name conflicts in general.

The use of namespaces makes it possible to use identical names with different meanings in different vocabularies. Within a namespace, each name used must be unique, but the same name may be used in different namespaces. The need to define namespaces is also given by the properties of XML itself, since XML basically supports a free choice of element names and attribute names. This inevitably raises the problem that the same names with different meanings may be used.

The identification of namespaces

For the identification of namespaces a URI reference (Uniform Resource Identifier) - mostly this is a Uniform Resource Locator( URL), thus an Internet address - is necessary. This address is defined only as a reference, which must exist just as little as that for the further processing of the XML document no connection to the Internet must exist. One uses here only the default that URI references must be generally unique, in order to present to the XML processor a not to be confused name for the name range. A URI reference is also only unique in this context if the URI is case-sensitive. One more note should be made here: the W3C itself maintains its own namespaces and stores corresponding references under the associated URLs - but no generally valid name lists. However, no XML processor branches there either when processing a namespace in an XML document. Thus only a formalism to be kept is coined.

The namespaces in an XML document are declared via the xmlns attribute - which stands for XML namespace - and two possible types are supported: 1. the agreement of a default namespace and 2. the agreement of the namespace with prefixes.

For the agreement of a default namespace, a name in an element is defined as a value of the xmlns attribute with the following syntax.

Example of an XML namespace

Example of an XML namespace

It should be noted that the default namespaces are not valid for attributes but only for elements. The attributes themselves do not belong to any namespace.

A prefix can be used to explicitly indicate that a name belongs to a defined namespace. The prefix is assigned when the namespace is declared, and a colon is used to separate it. This prefix is intended only for the sake of namespace abbreviation and clarity, but is replaced by the URL address when processed by the XML processor. The syntax for this is:

Assignment of a name to a defined namespace

Assignment of a name to a defined namespace

The entire name then consists of: nameprefix:elementname

and is referred to as a so-called qualified name, or the element name as a local name.

A final note on the topic of Document Type Definition (DTD) and namespaces. It should be noted here that the syntax for DTDs was defined before the W3C recommendation on namespaces. Thus, DTDs also do not support the concept of namespaces and, as a result, the elements and attributes, including a possible prefix, must be explicitly specified in a DTD. This makes a DTD easily confusing and difficult to read. The situation is different with XML Schema - there the concept of the language already integrates the use of namespaces in the specification.

Informations:
Englisch: namespace XML
Updated at: 17.11.2013
#Words: 660
Links: method, attribute, uniform resource identifier (URI), indium (In), document type definition (XML) (DTD)
Translations: DE
Sharing:    

All rights reserved DATACOM Buchverlag GmbH © 2024