Bugzilla – Bug 805
Spurious error "The shape attribute on the a element is obsolete"
Last modified: 2011-01-06 14:46:04 CET
Attempting to validate http://www.djangoproject.com/ as XML (it is XHTML served as text/html), I get a bogus error on each <a> element, like this: Error: The shape attribute on the a element is obsolete. Use area instead of a for image maps. From line 27, column 18; to line 27, column 57 id="logo"><a href="http://www.djangoproject.com/"><img s There is no 'shape' attribute on these elements. See http://validator.nu/?doc=http%3A%2F%2Fwww.djangoproject.com%2F&parser=xmldtd&laxtype=yes&showsource=yes
I'm able to reproduce this problem with the following minimal document: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> </head> <body> <a href="foo">bar</a> </body> </html> But I find that if I omit the doctype, the problem does not occur. I also find that if I choose "XML; don't load external entities" instead of "XML; load external entities" (parser=xml instead of parser=xmldtd), the problem does not occur. So, it seems like the cause has something to do with the XML parser reading the DTD from the doctype, and doing some attribute defaulting or something. Note that I tried it also with the XHTML1 Strict DTD instead of Transitional. So whatever the cause is, it's not something unique to the Transitional DTD. Anyway, I'll poke around more and try to see if I can get this figured out.
So in the XHTML 1.0 DTDs (and in the cached copies of those that validator.nu uses), I find that those DTDs set a default value of "rect" for the shape attribute on the a element: <!ATTLIST a ... shape %Shape; "rect" http://www.w3.org/TR/xhtml1/dtds.html#dtdentry_xhtml1-transitional.dtd_a So what's happening when you choose "XML; load external entities" is that you're instructing validator.nu to load/read/parse the DTD, following the rules in the XML spec. And what the XML spec says about this case is here: http://www.w3.org/TR/REC-xml/#sec-attr-defaults "If the declaration is neither #REQUIRED nor #IMPLIED, then the AttValue value contains the declared default value... When an XML processor encounters an element without a specification for an attribute for which it has read a default value declaration, it must report the attribute with the declared default value to the application." In other words, this is essentially what happens: 1. The parser reads your source and finds an instance of the <a> element: <a href="http://www.djangoproject.com/">...</a> 2. You've told validator.nu to have the parser load the DTD, so it checks the DTD, and "reads a default value declaration" for the shape attribute on the <a> element. 3. The parser finds that instance of <a> in your source to not have a "specification for an attribute for which it has read a default value declaration" -- the shape attribute. 4. The parsing rules in the XML spec require the parser to "report the attribute with the declared default value to the application" -- in other words, the parser is required to tell validator.nu that your <a> element does in fact have a shape attribute with the value "rect". So validator.nu is just following the rules in the XML spec, and according to those rules, the error message you're seeing is expected behavior. But clearly that behavior is confusing in this case. The only thing that comes to mind immediately as a way we could address this is, we could have the XML parser emit a warning any time it does attribute defaulting like this. Something like, "Warning: Adding the shape attribute to the a element as required by XML parsing rules when loading DTDs".
Luke, I made a change in my workspace that causes the XML parser to emit a warning when it does attribute defaulting, and I went ahead and deployed it for demo purposes here: http://www.w3.org/html/check Please give a try and let me know if you think it helps or hurts. Due to the XML spec requiring that conformant parsers do attribute defaulting, I don't think we can change the parser behavior to ignore the defaulted attributes in DTDs that it loads. And at the validator.nu application level, the parser exposes defaulted attributes in exactly the same way it exposes attributes that are explicitly specified in a document. So the only thing I can think to do to help mitigate the confusion that behavior causes is to have the parser emit a warning when it does attribute defaulting, and to have validator.nu pick that up and report it.
https://bitbucket.org/validator/xmlparser-patches/qseries?apply=t&qs_apply=warn-default-attrs
https://bitbucket.org/validator/xmlparser/changeset/5922374b5f63