The following document is not valid acording to XML 1.0. The xmlns attribute is not properly declared. However, Xerces-J incorrectly reports it as valid. As near as I can tell for the last several releases Xerces-J has not validated xmlns and xmlns:prefix attributes. This is correct behavior for schemas but not for DTDs. In order to be DTD-valid, all namespace declaration attributes used in the document must be declared. They do not get any special exemptions from the rules of XML 1.0: <?xml version="1.0"?> <!DOCTYPE test [ <!ELEMENT test (#PCDATA)> ]> <test xmlns="http://www.ibiblio.org/xml/"> content </test> The example here just uses an xmlns attribute on the root element, but I've noted this behavior with many different kinds of xmlns and xmlns:prefix attributes in different places.
u have written "In order to be DTD-valid, all namespace declaration attributes used in the document must be declared. They do not get any special exemptions from the rules of XML 1.0:" i could not find such thing anywhere, can u give me pointers? i feel this is correct behavior for DTD also and parser is behaving correctly.
Coincidentally, I noticed this same issue a couple of months ago, but never submitted a bug report for it. The following in an excerpt from a note on the topic, with relevant pointers to the XML 1.0 (2nd Ed.) Recommendation. I believe that if validation is requested, the parser should produce a validation error for the document, because the xmlns:ns attribute hasn't been declared in the DTD. The definition of start-tags and empty-element tags [1] specifies that the attributes must satisfy validity constraint [2] - namely, that the attribute must have been declared, and that the value of the attribute must be of the correct type. The Namespaces recommendation [3] indicates that a namespace is declared using the reserved family of attributes "xmlns" and those that begin with "xmlns:", but it doesn't indicate that such attributes are themselves "predeclared" in any sense. [1] http://www.w3.org/TR/2000/REC-xml-20001006#sec-starttags [2] http://www.w3.org/TR/2000/REC-xml-20001006#ValueType [3] http://www.w3.org/TR/1999/REC-xml-names-19990114/#ns-decl
The attribute name xmlns, which is used to declare the default namespace, is associated with the namespace name http://www.w3.org/2000/xmlns/ The above link gives you the information about xmlns.
You are right, however, we don't have time to fix this bug in Xerces1. If you provide a patch we will apply it. The behaviour is correct in the latest Xerces2 beta3 release
Re-opening so I can return it as a duplicate.
*** This bug has been marked as a duplicate of 1917 ***