Interview Questions

Do the default values of xmlns attributes declared in the DTD apply to the DTD?

XML Interview Questions and Answers


(Continued from previous question...)

68. Do the default values of xmlns attributes declared in the DTD apply to the DTD?

No.
Declaring a default value of an xmlns attribute in the DTD does not declare an XML namespace for the DTD. (In fact, no XML namespace declarations apply to DTDs.) Instead, these defaults (declarations) take effect only when the attribute is instantiated on an element. For example:
<?xml version="1.0" ?>
<!DOCTYPE google:A [
<!ELEMENT google:A (google:B)>
<!ATTLIST google:A
xmlns:google CDATA #FIXED "http://www.google.org/">
<!ELEMENT google:B (#PCDATA)>
]>
<google:A> <========== Namespace declaration takes effect here.
<google:B>abc</google:B>
</google:A> <========= Namespace declaration ends here.
For more information, see question 7.2. (Note that an earlier version of MSXML (the parser used by Internet Explorer) did use fixed xmlns attribute declarations as XML namespace declarations, but that this was removed in MSXML 4.

(Continued on next question...)

Other Interview Questions