|>> English << | česky | Español | Türkçe | Português | Nederlands | Français | Deutsch | По-русски | Italiano | 中文 | ქართული | Magyar | Polski||ZVON > Tutorials > Namespace Tutorial|
|Intro / Search / ZVON|
In this tutorial three artificial sets of elements will be used: lowercase, uppercase ve xnumber sets. For a human reader it is an easy task to recognize the set an element belongs to. But the computer does not have the apriori knowledge the human has and so the logic would have to be programmed into the handling program.
For the namespace declarations reserved attributes starting with xmlns are used. You can declare a namespace on each element you are using, but this approach is tiring and the resulting code is hard to read.
Declaring namespaces with each element as in Example 2 would be very unconvenient and error prone. The standard provides several ways how to accomplish the task. The namespace declaration given for the current element is also valid for all elements occuring inside the current one (for all children and descendants).
It is a common practice to declare all namespaces within the root element.
The value of the xmlns attribute identifies the namespace, not the prefix. In this example, all elements belongs to the same namespace although different prefixes are used.
While in the Example 5 all elements belonged to the same namespace although they had different prefixes, in this case they belong to different namespaces although they have the same prefixes.
Namespaces do not have to be declared explicitly with prefixes. The attribute xmlns defines the default namespace which is used for the element where it occures and for its children and descendants.
Even if default namespaces are used, namespaces for chosen elements can still be explicitly stated.
Default namespaces can be undeclared if an empty string is used for its value.
Attributes can be also explicitly assigned to the given namespace.
Attributes without a prefix never belongs to any namespace.
The attributes do not belong to any namespace even if a default namespace is defined for the relevant element.
The namespace declaration is restricted to the scope of the element where it is declared.
And the last example to enjoy.