Is this html declaration repetitive
I have a doctype declaration as seen in the first 2 开发者_如何学JAVAlines.
In the third line, the html tag also has some xmlns declaration and xml:lang and lang. Is any of these xmlns, xml:lang, or lang repetitive? Do they duplicate anything from the doctype. I'd like to keep the doctype and remove all the declarations on the third line if they're repetitive.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
</html>
They're not repetitive. The XML namespace for XHTML and the doctype declaration aren't the same. Neither are the xml:lang
and lang
attributes. The XHTML 1.0 specification requires that all of these are included.
The attribute list for the <html>
element as described by the XHTML 1.0 Strict DTD is as follows:
<!ATTLIST html
%i18n;
id ID #IMPLIED
xmlns %URI; #FIXED 'http://www.w3.org/1999/xhtml'
>
(where %i18n
is an internal entity that represents the xml:lang
, lang
and dir
internationalization attributes, see below)
Notice the fourth line. It says that xmlns
is an attribute of a given URI value, and is fixed at that very namespace URL. That means if you omit the attribute or give it a different namespace, your document is invalid strict XHTML.
The %i18n
entity corresponds to these attributes:
<!-- internationalization attributes
lang language code (backwards compatible)
xml:lang language code (as per XML 1.0 spec)
dir direction for weak/neutral text
-->
<!ENTITY % i18n
"lang %LanguageCode; #IMPLIED
xml:lang %LanguageCode; #IMPLIED
dir (ltr|rtl) #IMPLIED"
>
The lang
attribute is for backwards compatibility (i.e. HTML ≤ 4.01), and xml:lang
is described by XML 1.0 (hence the xml
namespace seen here). I'm not too sure of the exact reason why xml:lang
should precede lang
, but it makes sense given that XHTML is merely HTML "reworded" into XML syntax (so to speak).
The dir
attribute defaults to ltr
(left-to-right text) if not specified, hence it's not a required attribute.
To conform to the strict XHTML standard as your DOCTYPE indicates, you have to specify the xmlns
attribute.
The root element of the document must designate the XHTML namespace using the xmlns attribute [XMLNAMES]. The namespace designator for XHTML is "http://www.w3.org/1999/xhtml".
Reference point #3 from http://www.w3.org/TR/xhtml11/conformance.html
No, the doctype and the namespace of the xml document are different things.
If you're using XHTML, then (as per the other comments here) you need to specify all of that stuff. It's all required for your page to conform to the spec (XHTML pages will fail if they don't conform 100% to the spec).
However your question states that you'd like to simplify your code. As things stand, using XHTML, you can't. But if you switch to the HTML5 spec, then you can simplify things considerably.
HTML5 doesn't require a complex doctype, and it doesn't require any XML namespace declarations. An HTML5 document would look like this:
<!DOCTYPE html>
<html>
....
</html>
I'm sure you'll agree, that's much simpler and easier to read.
The great news is that you can do this without changing anything else or losing any functionality. All current browsers will work with this code, even if they're not explicitly HTML5-compatible.
No, there is nothing like duplication.
We can mention both the lang
and xml:lang
attributes.
The value of the xml:lang
attribute takes precedence
xmlns
must be there if the Doctype is in Strict mode.
精彩评论