Interview Questions

How do I undeclare an XML namespace prefix?

XML Interview Questions and Answers


(Continued from previous question...)

71. How do I undeclare an XML namespace prefix?

In version 1.0 of the XML namespaces recommendation, you cannot "undeclare" an XML namespace prefix. It remains in scope until the end of the element on which it was declared unless it is overridden. Furthermore, trying to undeclare a prefix by redeclaring it with an empty (zero-length) name (URI) results in a namespace error. For example:

<google:A xmlns:google="http://www.google.org/">
<google:B>
<google:C xmlns:google=""> <==== This is an error in v1.0, legal in v1.1.
<google:D>abcd</google:D>
</google:C>
</google:B>
</google:A>

In version 1.1 of the XML namespaces recommendation [currently a candidate recommendation -- February, 2003], you can undeclare an XML namespace prefix by redeclaring it with an empty name. For example, in the above document, the XML namespace declaration xmlns:google="" is legal and removes the mapping from the google prefix to the http://www.google.org URI. Because of this, the use of the google prefix in the google:D element results in a namespace error.

(Continued on next question...)

Other Interview Questions