HelmBurger
HelmBurger

Reputation: 1298

XML not well formed

When I put the end tag on link in head of html page, the W3C Validator shows well-formed.

But then when I validate HTML it says "Stray end link tag".

How can I validate both HTML and XML at same time?

Upvotes: 0

Views: 104

Answers (1)

Jukka K. Korpela
Jukka K. Korpela

Reputation: 201798

Appendix C of XHTML 1.0 recommends syntax like

<link rel="stylesheet" href="foo.css" />

That is, the XML “self-closing” empty element tag syntax, with a space before the slash /. The space is actually not needed any more (browsers that required it have become extinct), so you can also write

<link rel="stylesheet" href="foo.css"/>

This works on all browsers. Formally, you should not use it HTML 4.01 (see a longish explanation in Empty elements in SGML, HTML, XML, and XHTML), and it may cause a validation error, depending on context (for link, it does).

There’s no way to make the same document both a conforming HTML 4.01 document and a conforming XHTML 1.0 document. Normally, there is no need either.

In HTML5, it’s different: the “self-closing” syntax is allowed both in HTML serialization and in XML (XHTML) serialization.

Upvotes: 0

Related Questions