>> English << | česky | Español | Türkçe | Português | Nederlands | Français | Deutsch | По-русски | Italiano | 中文 | ქართული | Magyar | Polski | ZVON > Tutorials > Namespace Tutorial |
Intro / Search / ZVON |
Example 1 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. |
Example 2 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. |
Example 3 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). |
Example 4 It is a common practice to declare all namespaces within the root element. |
Example 5 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. |
Example 6 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. |
Example 7 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. |
Example 8 Even if default namespaces are used, namespaces for chosen elements can still be explicitly stated. |
Example 9 Default namespaces can be undeclared if an empty string is used for its value. |
Example 10 Attributes can be also explicitly assigned to the given namespace. |
Example 11 Attributes without a prefix never belongs to any namespace. |
Example 12 The attributes do not belong to any namespace even if a default namespace is defined for the relevant element. |
Example 13 The namespace declaration is restricted to the scope of the element where it is declared. |
Example 14 And the last example to enjoy. |