Interview Questions

How do I use the default XML namespace to refer to attribute names in an XML namespace?

XML Interview Questions and Answers


(Continued from previous question...)

76. How do I use the default XML namespace to refer to attribute names in an XML namespace?

You can't.
The default XML namespace only applies to element type names, so you can refer to attribute names that are in an XML namespace only with a prefix. For example, suppose that you declared the http://http://www.w3.org/to/addresses namespace as the default XML namespace. In the following, the type attribute name does not refer to that namespace, although the Address element type name does. That is, the Address element type name is in the http://http://www.fyicneter.com/ito/addresses namespace, but the type attribute name is not in any XML namespace.

<!-- http://http://www.w3.org/to/addresses is the default XML namespace. -->
<Address type="home">

To understand why this is true, remember that the purpose of XML namespaces is to uniquely identify element and attribute names. Unprefixed attribute names can be uniquely identified based on the element type to which they belong, so there is no need identify them further by including them in an XML namespace. In fact, the only reason for allowing attribute names to be prefixed is so that attributes defined in one XML language can be used in another XML language.

(Continued on next question...)

Other Interview Questions