Interview Questions

How do I override an XML namespace declaration that uses a prefix?

XML Interview Questions and Answers


(Continued from previous question...)

69. How do I override an XML namespace declaration that uses a prefix?

To override the prefix used in an XML namespace declaration, you simply declare another XML namespace with the same prefix. For example, in the following, the google prefix is associated with the http://www.google.org/ namespace on the A and B elements and the http://www.bar.org/ namespace on the C and D elements. That is, the names A and B are in the http://www.google.org/ namespace and the names C and D are in the http://www.bar.org/ namespace.

<google:A xmlns:google="http://www.google.org/">
<google:B>
<google:C xmlns:google="http://www.bar.org/">
<google:D>abcd</google:D>
</google:C>
</google:B>
</google:A>

In general, this leads to documents that are confusing to read and should be avoided.

(Continued on next question...)

Other Interview Questions