2
votes

I'm reading this page from W3Schools about XHTML where it says that <!DOCTYPE> is mandatory for XHTML documents.

My question is merely theoretical: Where does this rule come from?

I mean, I've read many tutorials about XML, but none says that there must always be a DOCTYPE declaration, it is needed only when validation is necessary. So, XHTML is a XML document, I've tried to read the XHTML DTD (strict) but I didn't find a line which says that the DOCTYPE is mandatory.

2
The fact that XHTML is an XML application does not mean that every rule applying to XHTML must apply to all XML documents. XML documents don't all need xmlns attributes either. - Mr Lister
W3schools is wrong. In XHTML 5 the doctype is optional - Alohci

2 Answers

2
votes

<!DOCTYPE> is not mandatory in XML

It is mandatory in XHTML as @Lashane has answered. It (doctypedecl) is optional in XML:

[1]   document    ::= prolog element Misc*
[22]  prolog      ::= XMLDecl? Misc* (doctypedecl Misc*)?
[28]  doctypedecl ::= '<!DOCTYPE' S Name (S ExternalID)? S? ('[' intSubset ']' S?)? '>'

XHTML can impose additional requirements and still be XML as long as the additional requirements do not contradict those of XML. This DOCTYPE requirement is completely consistent with XML. There is no contradiction.

1
votes

this rule comes from xhtml standard

There must be a DOCTYPE declaration in the document prior to the root element. The public identifier included in the DOCTYPE declaration must reference one of the three DTDs found in DTDs using the respective Formal Public Identifier. The system identifier may be changed to reflect local system conventions.