user3205479
user3205479

Reputation: 1523

Why XHTML markup does not generate parsing error?

I started learning the basics of HTML and I have studied differences between XHTML and HTML. I have noticed XHTML is much stricter. Consider below markup

<?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">  
<html xmlns="http://www.w3.org/TR/xhtml1" xml:lang="en" lang="en">
<head>
   <title>Every document must have a title</title>
 </head> 
<body>
  <b><p>hey</b></p><br>
</body>
</html>

I have not properly nested the tags and <br> is not properly closed in XHTML but it does not raise any parsing error and when I have saved the file as test.xhtml then it raised parsing error. So how to actually create XHTML files and also how to use XHTML in HTML5? and could anyone explain me that files saved with .xhtml are XHTML files and with .html are treated as HTML files?

Iam using google chrome. I understand the differences but unable to view practically in the browser. Could anyone help me figuring this out.

Upvotes: 0

Views: 106

Answers (1)

Quentin
Quentin

Reputation: 943801

Most web browsers have XML and HTML parsers. These use different rules.

In general, the rules they follow are:

  • If the document has one of various XML content-types and the document in in the XHTML name space: Use the XML parser
  • If the document has a text/html content-type then use the HTML parser
  • If the document is loaded from a local file and has a .xhtml file extension, then treat it as having the content-type application/xhtml+xml
  • If the document is loaded from a local file and has a .html file extension, then treat it as having the content-type text/html

Upvotes: 2

Related Questions