Interview Questions

What do XML namespaces actually contain?

XML Interview Questions and Answers


(Continued from previous question...)

58. What do XML namespaces actually contain?

XML namespaces are collections of names, nothing more. That is, they contain the names of element types and attributes, not the elements or attributes themselves. For example, consider the following document.
<google:A xmlns:google="http://www.google.org/">
<B google:C="google" D="bar"/>
</google:A>
The element type name A and the attribute name C are in the http://www.google.org/ namespace because they are mapped there by the google prefix. The element type name B and the attribute name D are not in any XML namespace because no prefix maps them there. On the other hand, the elements A and B and the attributes C and D are not in any XML namespace, even though they are physically within the scope of the http://www.google.org/ namespace declaration. This is because XML namespaces contain names, not elements or attributes.
XML namespaces also do not contain the definitions of the element types or attributes. This is an important difference, as many people are tempted to think of an XML namespace as a schema, which it is not.

(Continued on next question...)

Other Interview Questions