sandbox
sandbox

Reputation: 2679

XHTML doctype in eclipse

When using the inbuilt template for my html pages in eclipse, I get the following code appended prior to xhtml doctype: <?xml version="1.0" encoding="ISO-8859-1" ?> Does this code affects the html pages?

Upvotes: 0

Views: 405

Answers (2)

Tim
Tim

Reputation: 9489

No it doesn't, your html is still valid and readable for every browser. (However, it will put IE into quirks mode for every version below IE9 — see @Rob’s comment.)

Because you are using xhtml, which is basicly a type of xml, the browser needs some kind of encoding for the document.

See w3c:

Historically, the character encoding of an HTML document is either specified by a web server via the charset parameter of the HTTP Content-Type header, or via a meta element in the document itself. In an XML document, the character encoding of the document is specified on the XML declaration (e.g., <?xml version="1.0" encoding="EUC-JP"?>). In order to portably present documents with specific character encodings, the best approach is to ensure that the web server provides the correct headers. If this is not possible, a document that wants to set its character encoding explicitly must include both the XML declaration an encoding declaration and a meta http-equiv statement (e.g., <meta http-equiv="Content-type" content="text/html; charset=EUC-JP" />). In XHTML-conforming user agents, the value of the encoding declaration of the XML declaration takes precedence.

BTW this is only if you use another char-set than UTF-8 or UTF-16. If you use default UTF8 or UTF016 there are some exceptions. See W3C (again).

Upvotes: 1

Jukka K. Korpela
Jukka K. Korpela

Reputation: 201828

The construct <?xml version="1.0" encoding="ISO-8859-1" ?> is not a doctype issue but an XML declaration, which may be used at the start of any XML document, whether it has a document type declaration or not and whether it happens to be XHTML or something else. According to the XHTML 1.0 specification, “An XML declaration is not required in all XML documents; however XHTML document authors are strongly encouraged to use XML declarations in all their documents. Such a declaration is required when the character encoding of the document is other than the default UTF-8 or UTF-16 and no encoding was determined by a higher-level protocol.”

So if the XHTML document is in fact ISO-8859-1 encoded, the XML declaration is useful and recommendable. If not, then it’s wrong information.

Upvotes: 1

Related Questions