XML Namespace

tutorial and example
tutorial and example

Namespace is set of unique names. It is used to avoid element name conflict in XML document. A name space is identified by URI (Uniform Resource Identifiers).

Namespace Declaration

Namespace is declared using reserved attributes. Attribute name must be started with xmlns:

Syntax

  • Namespace must be starts with the keyword xmlns.
  • The word name is the Namespace prefix.
  • The URL in the Namespace identifier.

Example

In above Example prefix is cont, and Namespace identifier as www.tutorialandexample.com/javascript-tutorial

Local Namespace

When we define the namespace, we defined it against the root element. It means that the namespace was to be used for the whole document, when we prefixed all child elements with the same namespace.

Example of Local Namespace

Default Namespace

A default namespace is one where prefix is not apply. We can also define namespace against child node. We use multiple namespaces within the same document if required.

Example of Default Namespace