Do I need to declare XML on a page using XYTML doctype?

I saw some conflicting information that an XHTML document should also declare itself as XML.

<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

However, in other places I see (including w3.org) that DOCTYPE should be the first declaration .

Since W3 says this, it should be true. However, I probably have several pages / applications lying around this that follow the first method. What are my risks?

Change I just ran the page through the W3 Validator with and without XML declaration, and it went like paths. At this point, I assume that this is just "style."

+6
html xml xhtml doctype
source share
4 answers
 <?xml version="1.0" encoding="utf-8"?> 

... is the default version and encoding for XML, so you don't need it at all. If you use XHTML as text / html, this probably shouldn't be.

However, in other places I see (including w3.org) that DOCTYPE should be the first tag.

There seems to be some confusion ... DOCTYPE is not a tag, and none of them are <? xml? > (which is called an XML declaration and looks like a processing instruction, but it is not one of those).

If you include both of these documents, you must first specify the XML declaration. The trick is that the IE6 DOCTYPE sniffer only detects DOCTYPE standards if they are the first on the page, which means you cannot use the XML declaration and you must adhere to the XML 1.0 and UTF-8 encoding (which is not surprising loss) .

+9
source share

From the XHTML 1.1 specification :

An XML declaration like the one above is not required in all XML documents. XHTML document authors MUST use XML declarations in all of their documents. XHTML document authors MUST use an XML declaration when the character encoding of a document is different from the default UTF-8 or UTF-16 and there is no encoding defined by a higher-level protocol.

http://www.w3.org/TR/xhtml11/conformance.html

+4
source share

http://validator.w3.org/ only accepts <? xml> to <! DOCTYPE>. Another way (doctype before? Xml) will not be checked.

+4
source share

I never turned it on (always left with doctype only) and w3c says my XHTML 1.0 Strict projects are "valid".

+2
source share

All Articles