I think it is not exactly that we are declaring namespaces inside the DTD. The only requirement is that name strings are valid XML names for elements and attributes. The DTD will be successfully validated against the xml for one small change as shown below -
<foo:A xmlns:foo="http://www.foo.org/">
<foo:B>abc</foo:B>
</foo:A>
We need to add the namespace declaration for the instance document as shown above. Otherwise, the validator complains that foo is an undeclared namespace.
I expected that we can even do away without adding the namespace declaration as xmlns:foo as the attribute "xmlns:foo" has a #FIXED value of "http://www.foo.org/". But the validator seem to be strictly looking as what is in there in the instance document.
I ran a little
test with the
java DOM parser code without supplying the "xmlns:foo" attribute as shown below -
<foo:A>
<foo:B>abc</foo:B>
</foo:A>
The parser successfully found this attribute from the DTD definition as it gave me the following output -
RootElement--foo:A
No. of children for root node 1
foo:A=null(ELEMENT_NODE)
ATTR::xmlns:foo=http://www.foo.org(ATTRIBUTE_NODE)
foo:B=null(ELEMENT_NODE)
#text=abc(TEXT_NODE)
The output is indented to show the correct depth of heirarchy.
This shows that it matters as to who is looking at the instance document, the validator or the parser. The validator doesn't seem to be caring about the #FIXED attribute and expects the namespace declaration for "foo". The parser is smart enough to resolve this.
Anyone please correct me for any mistakes.
Thanks.